Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript array of objects check for key [duplicate]

enter image description here

So my question how can I check this array of objects by "key" for eg I want to check if the key 3892 is there, I have tried with indexOf but no luck, I can't use a loop.

like image 972
Uffo Avatar asked Dec 18 '25 21:12

Uffo


1 Answers

You can use some() and hasOwnProperty()

var array = [{3892: 'value'}, {1234: 'value'}];

var check = array.some(obj => obj.hasOwnProperty(3892));
console.log(check)
like image 146
Nenad Vracar Avatar answered Dec 20 '25 11:12

Nenad Vracar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!