Skip to content
Advertisement

Find a specific object in an array of objects

I don’t understand because I use the method “find” but I get “undefined”… My data :

JavaScript

I would like to have only the object with the ID 2 for example.

So I wrote :

JavaScript

But it does not work… I always get “undefined”

Thanks for help

Advertisement

Answer

ID is a number, therefore you need to remove the quotes around 2

JavaScript

and the operator === in Javascript means that 2 should be equal to “2” as in value and type

reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement