The problem of javascript array push

var I is a variable,
var arr = [];
I want to implement that I is a number, so I add the empty object {name:""} of name to my empty array a few times.
for example, if I is 1
, then arr = [{name:""}]
such as I is 2
arr = [{name:""}, {name:""}]
such as I is 3
arr = [{name:""}, {name:""}, {name:""}]
.

Apr.16,2021

let generateArray = function(i) {
    let arr = [];
    while(i--) {
        arr.push({ name: '' });
    }
    return arr;
}
generateArray(3);

is that so?


new Array(10).fill({name:''})

there is a problem with the above method. All values in the array point to the same reference. Change to:

Array.from({length:10}, () => ({name:''}))

new Array(10).fill(0).map(() => ({name: ''}))
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3d25d-34739.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3d25d-34739.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?