i am tryong to make an array and be able to find the objects inside the array but whenever i do that it always gives me only the firstindex
let merchandise = [
{
item:"Fan",
price:800,
},
{
item:"Television",
price:500,
},
{
item:"Headphone",
price:700,
},
{
item: "Refrigerator",
price: 1000,
}
];
merchandise.find(items => items = prompt('what do you want to buy'))
console.log(merchandise[0]);
2
Answers
In your example, this
merchandise.find(items => items = prompt('what do you want to buy'))
doesn’t make sense, because=
is not comparing. And then you just output first element of array to console.It should be like this 👇: