I'd like to make a JSON list with different values.
Here's the code that I am trying to do.
...
// This will contain different JSON data of friendObj
var friendList = [];
// It is just default format of JSON obj.
var friendObj={
name: "Kim",
age: "19",
country: "Korea"
}
// Nodejs Router
router.post("/...", function(req,res,next){
friendList = getFriendList(10);
...
});
// a function to get dump data.
fun getFriendList(n){
var list = [];
for (var i = 0 ; i < n ; i++){
list.push(friendObj);
list[i].name = "Lee";
// This will save different ages each loop.
list[i].age = i+20;
list[i].country = "America";
}
return list;
}
When I print it out, I get the friendObj with the same values with the last element. In this case, all the element would have Lee, 39, America.
But I want different values on each element.
What should I do?