JavaScript array of object -
i have written block of typescript code.
createarray():any [] { console.log("start"); var array = []; var nameobjects = ["dave", "mike", "dave1", "mike1"]; (var j = 0; j < nameobjects.length; j++) { (var = 1; < 9; i++) { array.push({ "hour": i, nameobjects }) } } console.log(array); return array; }
the output this:
{ hour: 1, nameobjects :{"dave", "mike", "dave1", "mike1"} }, { hour: 2, nameobjects :{"dave", "mike", "dave1", "mike1"} }
.....
{hour: 9, nameobjects :{"dave", "mike", "dave1", "mike1"} } }
i want output like:
{ hour: 1, dave:0, mike:0, dave1:0, mike1:0 }, { hour: 2, dave:0, mike:0, dave1:0, mike1:0 },
i have tried fix couldn't. please overcome issue
do mean this?
console.log("start"); var array = []; var nameobjects = ["dave", "mike", "dave1", "mike1"]; (var = 1; < 9; i++) { var item = { hour: }; (var j = 0; j < nameobjects.length; j++) { item[nameobjects[j]] = 0; } array.push(item); } console.log(array);
Comments
Post a Comment