Home » Javascript » How to Name an nested array object using javascript

How to Name an nested array object using javascript

Posted by: admin November 1, 2017 Leave a comment

Questions:

My tool Pa11y gives me output in below JSON format

var result=[{name:'A'},{name:'B;}]

I want it to refer it as below so that it can be stored in mongoDB

var result={person:[{name:'A'},{name:'B;} ]}

Please help

Answers:

You can just use your result as the value to a key in an object. The key can be named arbitrarily as you need it:

var result=[{name:'A'},{name:'B;}]

var person = {
    person: result
}