টার্নারি অপারেটর (?) এর সাথে মানচিত্র() ধারণাটি ব্যবহার করুন। আমাদের অবজেক্টের অ্যারে −
let firstCustomerDetails =
[
{firstName: 'John', amount: 100},
{firstName: 'David', amount: 50},
{firstName: 'Bob', amount: 80}
];
let secondCustomerDetails =
[
{firstName: 'John', amount: 400},
{firstName: 'David', amount: 70},
{firstName: 'Bob', amount: 40}
]; ধরা যাক, রাশির বৈশিষ্ট্য অনুসারে আমাদের অবজেক্টের অ্যারে ফিল্টার করতে হবে। সবচেয়ে বেশি পরিমাণে একজনকে বিবেচনা করা হয়।
উদাহরণ
let firstCustomerDetails =
[
{firstName: 'John', amount: 100},
{firstName: 'David', amount: 50},
{firstName: 'Bob', amount: 80}
];
let secondCustomerDetails =
[
{firstName: 'John', amount: 400},
{firstName: 'David', amount: 70},
{firstName: 'Bob', amount: 40}
];
var output = firstCustomerDetails.map((key, position) =>
key.amount > secondCustomerDetails[position].amount ? key :
secondCustomerDetails[position]
);
console.log(output); উপরের প্রোগ্রামটি চালানোর জন্য, আপনাকে নিম্নলিখিত কমান্ডটি ব্যবহার করতে হবে -
node fileName.js.
এখানে, আমার ফাইলের নাম demo83.js।
আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবেPS C:\Users\Amit\JavaScript-code> node demo83.js
[
{ firstName: 'John', amount: 400 },
{ firstName: 'David', amount: 70 },
{ firstName: 'Bob', amount: 80 }
]