Im trying to parse list of list to json object.I need the following output but my logic is not correct to get the actual output but instead getting im appending the key/value to the array
Input (Array):
var arraysample =
[
[
["firstName", "Vasanth"],
["lastName", "Raja"],
["age", 24],
["role", "JSWizard"]
],
[
["firstName", "Sri"],
["lastName", "Devi"],
["age", 28],
["role", "Coder"]
]
];
Expected OUtput
[
{firstName: “Vasanth”, lastName: “Raja”, age: 24, role: “JSWizard”},
{firstName: “Sri”, lastName: “Devi”, age: 28, role: “Coder”}
]
My output:
[
[ 'firstName', 'Vasanth' ],
[ 'lastName', 'Raja' ],
[ 'age', 24 ],
[ 'role', 'JSWizard' ],
firstName: 'Vasanth',
lastName: 'Raja',
age: 24,
role: 'JSWizard'
],
[
[ 'firstName', 'Sri' ],
[ 'lastName', 'Devi' ],
[ 'age', 28 ],
[ 'role', 'Coder' ],
firstName: 'Sri',
lastName: 'Devi',
age: 28,
role: 'Coder'
]
]
MY Logic:
for(var i=0;i<arraysample.length;i++)
{
for(var j=0;j<arraysample[i].length;j++)
{
arraysample[i][arraysample[i][j][0]]=arraysample[i][j][1];
}
}