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

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.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

'Series' object is not callable Error / Statsmodels illegal variable name