how to insert new object with variable and value by the end of each object
-
24-06-2021 - |
Question
[{ date="4/7/2012", username="dealcloud", user_id=304378189},
{ date="4/7/2012", username="rizwanharun", user_id=18932327
},{ date="4/7/2012", username="aimtoendhunger", user_id=
122384145},{ date="4/7/2012", username="Sindy882", user_id=
705160297}}]
how can I insert a new object with variable and value by the end of each object. e.g i want to put location like date,username,user_id,location in each object
cheers for the help
Solution
Note: Your json syntax is wrong.
You can do something like this
var jsonObj = [{ "date":"4/7/2012", "username":"dealcloud", "user_id":304378189},
{ "date":"4/7/2012", "username":"rizwanharun", "user_id":18932327
},{ "date":"4/7/2012", "username":"aimtoendhunger", "user_id":
122384145},{ "date":"4/7/2012", "username":"Sindy882", "user_id":
705160297}}];
for(var i = 0; i < jsonObj.length;i++) {
jsonObj[i].location = "New location";
}
OTHER TIPS
remember that Objects doesn't have an order.
var ary = [{}, {}, {}];
for (i in ary) {
ary[i]['new_key'] = 'new val';
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow