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
習慣沉默2017-06-28 09:26:16
var arr = []
for (let i = 0; i < 10; i++) {
arr.push({a: i, b: i})
}
console.log(arr);
过去多啦不再A梦2017-06-28 09:26:16
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)
}
为情所困2017-06-28 09:26:16
Can be easily generated using fill
and map
of Array
:
var arr = (new Array(2)).fill(0).map(function(v, i) {
return {a: i + 1, b: i + 1};
});
黄舟2017-06-28 09:26:16
function createArray(n) {
return Array.from(new Array(n), (x, i) => ({ a: i + 1, b: i + 1 }));
}