get a single object from an array, according to condition by one of its keys

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


get a single object from an array, according to condition by one of its keys



I have an array of objects and I would like to obtain only the object that has the largest quantity, in this example the object with 'id': 4, and trying to use the filter property of javascript, but I have not achieved it, otherwise I can to achieve this?


[
{
"id": 1,
"quantity": 10,
"price": 80
},
{
"id": 2,
"quantity": 30,
"price": 170
},
{
"id": 3,
"quantity": 50,
"price": 230
},
{
"id": 4,
"quantity": 100,
"price": 100
}
]





If you only want one object, why use filter? Why not use .find?
– CertainPerformance
2 mins ago


filter


.find




1 Answer
1



let indexOfHighest = 1
arrayOfObject.map((obj,index) = {



})






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

J3r,NfV4HKZ7
SjSIbASwZ5hqK 30LRH AkBL9 Z,lviJ,MzyDqMKk,3,HbV 6WrI3oiK6XnTVcWlcp bbS,uy7AwD

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results