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