ধরা যাক অবজেক্টের মান সহ আমাদের সংখ্যাগুলি −
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'
]