কম্পিউটার টিউটোরিয়াল

জাভাস্ক্রিপ্টে অবজেক্ট ভ্যালুসহ সংখ্যা লুপ করে আউটপুট অ্যারেতে পুশ করা


মনে করুন নিচের মত অবজেক্ট ভ্যালুসহ সংখ্যাগুলো আছে −

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' ]

  1. জাভাস্ক্রিপ্ট array.values() মেথড

  2. জাভাস্ক্রিপ্টে অ্যারেতে নেস্টেড অবজেক্ট মানগুলোর যোগফল

  3. জাভাস্ক্রিপ্টে অবজেক্ট থেকে কি এবং মান বের করে অ্যারে তৈরি করা

  4. জাভাস্ক্রিপ্টে সংখ্যা অ্যারে কে ক্যারেক্টার কোড অবজেক্টে ম্যাপ করা