用对象值循环数字并将输出推入数组-JavaScript?
假设以下是带有对象值的数字-
var numberObject = { 2:90 , 6: 98 }在JavaScript中使用Array.from()-
var fillThePositionValue = Array.from({length: 15}, (value, index) => numberObject[index+ 1] || "novalue")示例
以下是使用对象值循环编号的代码-
var numberObject = { 2:90 , 6: 98 }
console.log("The actual object is=");
console.log(numberObject);
var fillThePositionValue = Array.from({length: 15}, (value, index) => numberObject[index+ 1] || "novalue")
console.log("After filling the value, the actual object is=");
console.log(fillThePositionValue)要运行上述程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo215.js。
输出结果
输出如下-
PS C:\Users\Amit\JavaScript-code> node demo215.js
The actual object is=
{ '2': 90, '6': 98 }
After filling the value, the actual object is=
[
'novalue', 90,
'novalue', 'novalue',
'novalue', 98,
'novalue', 'novalue',
'novalue', 'novalue',
'novalue', 'novalue',
'novalue', 'novalue',
'novalue'
]热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短