The array should be in the format of shuzu[{a:1,b:1},{a:2,b:2}]. Is to use a loop to generate key values and value values
var arr = [] for (let i = 0; i < 10; i++) { arr.push({a: i, b: i}) } console.log(arr);
Owner, take a look
var arr=[] for(let i=0;i<times;i++){ let obj={} obj.a=i+1 obj.b=i+1 arrr.push(obj) }
Can be easily generated using fill and map of Array:
fill
map
Array
var arr = (new Array(2)).fill(0).map(function(v, i) { return {a: i + 1, b: i + 1}; });
function createArray(n) { return Array.from(new Array(n), (x, i) => ({ a: i + 1, b: i + 1 })); }
Owner, take a look
Can be easily generated using
fill
andmap
ofArray
: