get a single object from an array, according to condition by one of its keys
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
}
]
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.
If you only want one object, why use
filter
? Why not use.find
?– CertainPerformance
2 mins ago