मान लें कि ऑब्जेक्ट वैल्यू वाले हमारे नंबर निम्नलिखित हैं -
var numberObject = { 2:90 , 6: 98 } जावास्क्रिप्ट में 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'
]