I have an array that is structured like this:
$scope.roomlist = [
{"roomid":"1", "tablecount":"10", "chaircount":"20", "whiteboards":"2"},
{"roomid":"2", "tablecount":"15", "chaircount":"30", "whiteboards":"2"},
{"roomid":"3", "tablecount":"10", "chaircount":"20"}];
The array values are dynamic and the array is generated by joining some tables. Whiteboards is one of the elements that may exist in all the rooms returned in the roomlist, may exist in some of the rooms as shown above or none of the rooms at all.
All I need to do is test to see if there is at least one room in the list which has the whiteboard object.
I have tried the indexOf test but it returns -1.
The code I executed, was
var myrooms = $scope.roomlist;
var results = myrooms.indexOf("whiteboards");
And then
console.log(results);
Any suggestions?
roomlistis an array of dictionaries, but you're indexing a string, the result is always going to be-1, meaning not found.