I have a JavaScript JSON object
const student = { name: "bob", age: 7, grade: 6 }
and I can send it to my Web API using the axios POST command with
JSON.stringify(student)
To build multiple student objects from an array by looping through and passing in values such as
let studentArr= []
const student = { name: studentArr[i]["name"], age: studentArr[i]["age"], grade: studentArr[i]["grade"}
In this example, i
represents the index for potentially up to 100 students. When working with one value of i
, everything functions correctly. My issue is creating a multi-element JSON object from the array. I am used to Newtonsoft.Json's ability to pull data from a SQL database and construct a JSON object. Simply using JSON.stringify(studentARR)
results in an empty output. I aim to send all student data to the Web API in one POST request so that the API can create a document for download.
I have tried several methods to achieve this task, but it seems like the approaches keep evolving. Any assistance on this matter would be greatly appreciated. Thank you.