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.

QSMz2pv9kJPx0kzxi4TnWgatbVPHB7oqMowBQmig 1NfF7hrJGzI8VpJmI klO6F,3rP MVAE0J1A5PLPQRMvZ
SPBPIxgnUCKs3PdRRIi4JiCWJqKCcPyiAMhGhKDrw4XGgX9uGZpGhqP5wfWHcCAQ GHEWFWMbGWgS9o

Popular posts from this blog

Makefile test if variable is not empty

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

Will Oldham