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

জাভাস্ক্রিপ্টে অ্যারে ও অবজেক্টের অ্যারেতে কমন আইটেমে প্রোপার্টি যোগ করা


প্রোপার্টি যোগ করতে map() ব্যবহার করুন। মনে করুন নিচের অ্যারেটি আছে −

const firstname = ['John', 'David', 'Bob'];

নিচের অবজেক্টের অ্যারেটি আছে −

const studentDetails = [    {       firstname: 'Carol',       marks: 78    },    {       firstname: 'Mike',       marks: 89    },    {       firstname: 'Bob',       marks: 86    } ];

 Example

নিচে কোডটি দেওয়া হলো −

const firstname = ['John', 'David', 'Bob']; const studentDetails = [    {       firstname: 'Carol',       marks: 78    },    {       firstname: 'Mike',       marks: 89    },    {       firstname: 'Bob',       marks: 86    } ]; const data = new Set(firstname); const result = studentDetails.map(tmpObject => {    if (data.has(tmpObject.firstname)) tmpObject.isPresent ="This is present";    else    tmpObject.isPresent = "This is not present";    return tmpObject; }); console.log(result);

প্রোগ্রাম চালাতে হলে নিচের কমান্ড ব্যবহার করতে হবে −

node fileName.js.

এখানে, আমার ফাইল নেম demo219.js।

আউটপুট

আউটপুট নিচের মত −

PS C:\Users\Amit\JavaScript-code> node demo219.js [    { firstname: 'Carol', marks: 78, isPresent: 'This is not present' },    { firstname: 'Mike', marks: 89, isPresent: 'This is not present' },    { firstname: 'Bob', marks: 86, isPresent: 'This is present' } ]

  1. জাভাস্ক্রিপ্ট অ্যারে মেথড: অ্যারেতে আইটেম যোগ ও সরানো

  2. জাভাস্ক্রিপ্ট অ্যারে অবজেক্ট গণনা করার উপায়

  3. জাভাস্ক্রিপ্ট Array length প্রপার্টি

  4. জাভাস্ক্রিপ্ট - অ্যারে অবজেক্টের length প্রোপার্টি