I am currently working on serializing a JavaScript object to JSON. Here is the code I have written so far:
var info = {};
...
$.each(data, function (key, value) {
info["name"] = value.name;
info["id"] = value.id;
});
...
console.log(JSON.stringify(info));
However, the output I receive is : {}
If anyone has suggestions on how to achieve the desired output like the one below, it would be greatly appreciated:
[{name: "John", id: "1"},
{name: "Anna", id: "2"},
{name: "Peter", id: "3"}]
Thank you.