I need assistance in modifying my code to generate dynamic buttons based on array elements instead of objects. Currently, the array I am using contains objects which is causing issues with tracking button status and other computations. Can you help me adjust the code to work with array elements?
var cars = [1,2,3,4,5,6];
$scope.btns = [];
for (var i = 0; i < cars.length; ++i) {
if(cars[i]!== 4 && cars[i]!==5)
{
$scope.btns.push({label: cars[i]+"/0/0", state: false });
$scope.btns.push({label: cars[i]+"/0/1", state: false });
}
}
console.log($scope.btns);
http://jsfiddle.net/kiranmca04/9j79djew/3/
current output:
[Object { label="1/0/0", state=false}, Object { label="1/0/1", state=false}, Object { label="2/0/0", state=false}, Object { label="2/0/1", state=false}, Object { label="3/0/0", state=false}, Object { label="3/0/1", state=false}, Object { label="6/0/0", state=false}, Object { label="6/0/1", state=false}]
Expected:
[{ label="1/0/0", state=false}, { label="1/0/1", state=false}, { label="2/0/0", state=false}, { label="2/0/1", state=false}, { label="3/0/0", state=false}, { label="3/0/1", state=false}, { label="6/0/0", state=false}, { label="6/0/1", state=false}]