Search code examples
javascriptfirebasefirebase-realtime-databasepolymerpolymerfire

Firebase web. Checking if an object in an array has a particular value


Im trying to compute if an array has a particular object that has a value which matches to what I want

The array is membersArray and here is where it comes from

<firebase-query
  id="querymembers"
  path="/members"
  order-by-child="crew"
  equal-to="[[routeData.key]]"
  data="{{membersArray}}">
</firebase-query>

The property

     _isUserAMember: {
       type: Boolean,
       computed: '_computeIfIsMember(membersArray,user)'
     },

And the function itself

  _computeIfIsMember: function(membersArray, user) {
    if(user && membersArray) {

     // var found = false;
     //  for(var i = 0; i < membersArray.length; i++) {
     //      if (membersArray[i].userid === user.uid) {
     //          found = true;
     //          break;
     //      }
     //  }
     //  return console.log(found);

      return console.log(membersArray.some(function(el) {
        return el.crew === username;
      }));

    }
  },

I keep getting false. What could I be doing wrong ?

This is how the members path looks like The array of members


Solution

  • console.log(typeof(this.membersArray)); // object

    Assuming that firebase query will only return a result if the user.uid equal-to the child, I don't think you need to recheck the result.