I want to get the name property value from this array and filter it’s value to a search input data to sort items
how can I do that?
items: [
{
id: 1,
name: 'Brown Brim',
imageUrl: 'https://i.ibb.co/ZYW3VTp/brown-brim.png',
price: 25
},
{
id: 2,
name: 'Blue Beanie',
imageUrl: 'https://i.ibb.co/ypkgK0X/blue-beanie.png',
price: 18
}
i tried using find() method but it return every object that has a name property
items.find(item => item.name).name.icludes(searchData)
2
Answers
try this
Use
newData
for your operation.UPDATED ANSWER
You said,
Reply me if this isn’t what you want,
1 => Get an array with only name fields in it.
2 => Then filter the new array according to
searchData
.3 => And sort the filtered array.
4 => finally all together.
OLD ANSWER
I’ve modified @sushildlh answer to a more safer version