Check if Object Value Exist inside Javascript Array

Known:

I have array of object like this

[{"jam":0,"jumlah":2400},{"jam":4,"jumlah":1200}]

Wanted:

I want to get the 4 value from jam

Question:

How to get it … ?

Answer:

We can get it with this code

let arrObjek = [{"jam":0,"jumlah":2400},{"jam":4,"jumlah":1200}]

let result = arrObjek.find(Objek => Objek.jam == 4)

Explain:

arrObjek.find(Objek => Objek.jam == 4), this code mean that javascript find the value of jam from Objek argument, result is an object which the matching value exist or if not matching then return ‘undefined’

Result:

{jam: 4, jumlah: 1200}

Thanks for reading

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *