使用对象值进行数字循环并将输出推送到数组 - 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'
]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP