I'm working on a Chrome extension an I've hit a wall.
- function isInQueue(id) {
-
chrome.extension.sendRequest({getQueueItems: 1}, function(response) {
-
var items = response.items;
-
if (items) {
-
for (var i = 0; i < items.length; i++) {
-
if ((items[i].id == id) == true) return true;
-
}
-
return false;
-
} else { return false; }
-
});
-
}
-
The request returns 'items' which is an array of objects. I am trying to see if another item
outside of the queue already exists
inside the queue. For example, there is an item on the outside with an id equal to '198677'. I know I already have an exact copy of that same item in my queue with the exact same id, '198677', however, when I test the two for equality
- (items[i].id == id) == true
, it returns false. I have checked the typeof both and they are both strings. I have tried using === and that hasn't worked. I tried adding zero to each of them to turn them into integers and that made the function return true when it was actually true, however, when I tested for true
- if (isInQueue(id) == true)
the conditional returned false.
This is all very confusing and frustrating for me. They're both strings, why doesn't it work?
Help is very much appreciated,
X Enterprises.