I have an object as follows -
var users = {
room: [1,2,3,4]
}
How do I find if the 3 exists in the room
array ?
I have an object as follows -
var users = {
room: [1,2,3,4]
}
How do I find if the 3 exists in the room
array ?
Use indexOf
:
var indexOfThree = users.room.indexOf(3);
if(indexOfThree != -1)
{
var three = users.room[indexOfThree];
}
else
{
console.log("not found");
}
it will return -1 if the element isn't found or else it's index in the array.