I have the following data being sent back to my Node/Express/Body-parser backend from a HandsOnTable.
[["Bob",null,"PhD",null],["Jane",null,"Masters",null],["Stew",null,"Degree",null]]
I'd like to be able to access each record (row) of data eg Bob, null, "PhD", null. This would give me my data to write out a document in Node.
When I do a console.log(req.body.table)
I get all of the data above - if I do a console.log(req.body.table[0])
I only get a single '['.
Any ideas?
req.body.table
is a string, that's why you get the first character only when doing req.body.table[0]
.
Parse it first
var parsed = JSON.parse(req.body.table);
var bob = parsed[0];
or if you're only consuming JSON, you can set Node Bodyparser to do it for you
app.use(bodyParser.json())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.