Waterman1 Waterman1 - 1 year ago 46
Javascript Question

Finding a value of a property in a JavaScript object inside an array

I have managed to pull some users back from my firebase database and am outputting them into the console

[Object, Object, Object, Object, Object]

Each object has:

gender: "male"
liked: "liked"
name: "ed"
not_liked: "liked"
username: "ed@ed.com"
useruid: "HSRcN6PuylXbv87kSWxKVtWffaI3"

how can I go through the array and say if the
with a value
then console.log() the associated name. In this case

my pseudo attempt :
if (Object.gender.includes('male')) {console.log('yes')} else {console.log('nah')}

Answer Source

Considering you are storing array in dataArray variable in javascript.

for (i = 0; i < dataArray.length; i++) { 

It will print username on console for userid=HSRcN6PuylXbv87kSWxKVtWffaI3