Am trying to loop over an object in angular-js and add an array to object foreach looped object , my code is as below but doesn't seem to work
vm.patients= [
{[ {"p1": "value1"} ]},
{[ {"p1": "value1"} ]},
{[ {"p1": "value1"} ]}
}];
for(var i=0; i < vm.patients.length; i++){
vm.patients[i].concat([{"z1": "z2",}]);`
}
My aim is to add {"z1": "z2",} to each loop ie the 3 loops arrays so that i end with below
vm.patients= [
{[ {"p1": "value1"},{"z1": "z2",} ]},
{[ {"p1": "value1"},{"z1": "z2",} ]},
{[ {"p1": "value1"},{"z1": "z2",} ]}
}];
concat however doesn't seem to work , any solution ?
vm.patientsis not an array. you need to use brackets[ ]to define an arraypatientsdoesn't have a length propertyfor inloop. However the order of properties iterated cannot be predicted or guaranteed.