+ 1
How to create an array of objects in javascript?
Imagine I have an object: var abc = { key1:'val1', key2:'val2', key3:'val3' }; Now, I want to create multiple objects of the same structure and I want them in an array named xyz[ ] without creating it explicitly every time and pushing it into the array. How to do that?
3 Respuestas
+ 1
arr = [{key:value},{key:value}]
or
arr.push({key:value})
+ 1
follow Lily Mea way
or
let arr = [];
arr = [...arr, {key:value}];