0

I am trying to return a boolean. I have this firebase list array

{
  "users" : {
    "AsvLATYdwhg6BB8rgMKn2n" : {
      "avatar" : "httDJid_DnWXwo/photo.jpg",
      "bio" : "say something about you!"
    },
    "SFmtrI0ta5PsqYkgqZuJ" : {
      "avatar" : "https://scontent.xx.fbcdn.net/v/t1.0-1/p100x100/103_n.jpg?o",
      "bio" : "say something about you!",
    }
  }

I want to check if one of the keys exist in the array.

 _isInArray(obj, list) {
    var i;
    for (i = 0; i < list.length; i++) {
        if (list[i] === obj) {
            return true;
        }
    }

      return false;
  }

Then I run it:

 if(_isInArray(SFmtrI0ta5PsqYkgqZuJo2EG, array) {
      console.log("Is in array");
    }else {
       console.log('not in array');
     }

But it seems I am missing something. It keeps just saying (not in array).

BTW: I am using angular2. Is there is a better way of doing this in typescript , if not vanilla JavaScript is just okay.

LearnToday
  • 2,762
  • 9
  • 38
  • 67

0 Answers0