I am trying to add json object to json array, but seems something wrong. what I'm getting array elements as -
0:{}
local:"con"
name:"con"
order:15
1:{}
local:"con"
name:"con"
order:15
what I'm expecting to happen -
0:{}
local:"con"
name:"con"
order:15
1:{}
local:"con2"
name:"con2"
order:16
I want points
array should have all unique json objects(with very for loop iteration) but it replaces all previously added json with current json(of current iteration) object and entire array has same json objects at all index positions
code -
for(var i = 0; i < machineDetails.length; i++)
{
machine['name'] = machineDetails[i].name;
machine['local'] = machineDetails[i].localName;
machine['order'] = machineDetails[i].orderInLine;
points.push(machine);
console.log(points);
}
in addition to above I tried points[i].push(machine);
but it does not work either and throws error as push property is not defined
. Please point me in right direction what i am missing or what should I do?