Js array problem

currently encountered a problem:

it is known that the length of the array is 5, there may be one, two or more values in the array, and the rest of the values want to be filled with "0".
in addition to the methods of the for loop, js has no native methods for arrays to do this.

Oct.14,2021

var arr = new Array(20);
arr[2] = 1;
arr[18] =2 ;
var r = Array.from(arr,(elem) => elem = elem === undefined ? 0 : elem);

try to see if it's what you want

ES5

var arr = new Array(20);
arr[2] = 1;
arr[18] =2 ;
arr = JSON.parse(JSON.stringify(arr)).map(function (elem) {
  return elem = elem === null ? 0 : elem
});
console.log(arr);

look at

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-1ea743f-47c15.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-1ea743f-47c15.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?