ধরা যাক নিম্নলিখিতটি আমাদের অবজেক্ট -
var employee =
[
{ name: "John", amount: 800 },
{ name: "David", amount: 500 },
{ name: "Bob", amount: 450 }
] আমাদের "পরিমাণ" মানকে 2 দিয়ে গুণ করতে হবে, শুধুমাত্র যদি পরিমাণটি 500-এর বেশি হয় অর্থাৎ প্রত্যাশিত আউটপুট হওয়া উচিত −
[
{ name: 'John', amount: 1600 },
{ name: 'David', amount: 500 },
{ name: 'Bob', amount: 900 }
] উদাহরণ
এখানে বস্তুর মান −
গুণ করার নমুনা উদাহরণvar employee =
[
{ name: "John", amount: 800 },
{ name: "David", amount: 500 },
{ name: "Bob", amount: 450 }
]
console.log("Before multiplying the result=")
console.log(employee)
for (var index = 0; index < employee.length; index++) {
if (employee[index].amount > 500) {
employee[index].amount = employee[index].amount * 2;
}
}
console.log("After multiplying the result=")
console.log(employee) উপরের প্রোগ্রামটি চালানোর জন্য, আপনাকে নিম্নলিখিত কমান্ডটি ব্যবহার করতে হবে -
node fileName.js.
এখানে, আমার ফাইলের নাম demo257.js।
আউটপুট
এটি কনসোলে নিম্নলিখিত আউটপুট তৈরি করবে -
PS C:\Users\Amit\javascript-code> node demo257.js
Before multiplying the result=
[
{ name: 'John', amount: 800 },
{ name: 'David', amount: 500 },
{ name: 'Bob', amount: 450 }
]
After multiplying the result=
[
{ name: 'John', amount: 1600 },
{ name: 'David', amount: 500 },
{ name: 'Bob', amount: 900 }
]