0

I have an array that looks like this:

userInterests [
  {
    "Status": "Interested",
    "$id": "-JncIGjhkuEx1Hq6Lzax",
    "$priority": null
  }
  {
    "Status": "Interested",
    "$id": "-TDIEGjhkuEx1Hq6Lzax",
    "$priority": null
  }
]

I need a boolean function that returns true or false if the id matches, so a function like this:

function isAnIDInArray(id) {

}

so that

isAnIDInArray(-JncIGjhkuEx1Hq6Lzax);

Would return true

Jordash
  • 2,926
  • 8
  • 38
  • 77

1 Answers1

1

Your function have to loop through all objects in the array and check evry id. So something like this:

function isAnIDInArray(id, array) {
    var i;
    for(i = 0; i < array.length; i++) {
        If(array[i].$id == id) {
            return true;
        }
    }
    return false;
}

Not sure if you can use '$' in javascript syntax tho.

Srneczek
  • 2,143
  • 1
  • 22
  • 26