473,395 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What is wrong with this conditional?

I'm working on a Chrome extension an I've hit a wall.

Expand|Select|Wrap|Line Numbers
  1. function isInQueue(id) {
  2.     chrome.extension.sendRequest({getQueueItems: 1}, function(response) {
  3.         var items = response.items;
  4.         if (items) {
  5.             for (var i = 0; i < items.length; i++) {
  6.                 if ((items[i].id == id) == true) return true;
  7.             }
  8.             return false;
  9.         } else { return false; }
  10.     });
  11. }
  12.  
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
Expand|Select|Wrap|Line Numbers
  1. (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
Expand|Select|Wrap|Line Numbers
  1. 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.
Dec 19 '10 #1
1 988
I figured it out. I actually have the queue stored in localStorage as stringified JSON.
Expand|Select|Wrap|Line Numbers
  1. function isInQueue(id, callback) {
  2.     var result = false;
  3.     var queue = localStorage["queue_rss"];
  4.     if (queue != undefined) {
  5.         var items = JSON.parse(queue).items;
  6.         if (items) {
  7.             for (var i = 0; i < items.length; i++) {
  8.                 if ((items[i].id == id) == true) {
  9.                   result = true;
  10.                   break;
  11.                 }
  12.             }
  13.         }
  14.     }
  15.     callback(result);
  16. }
Dec 19 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Eric Bragas | last post by:
What is this? <img src="{$ ImagesDir}/photo.gif"> I KNOW what an HTML image tag looks like. But what do you call that in the file source? Is it like a virtual directory in IIS? It's some type...
28
by: Madhur | last post by:
Hello what about this nice way to open a file in single line rather than using if and else. #include<stdio.h> void main() { FILE *nd; clrscr();...
1
by: mike | last post by:
Error 1 The type 'ADODB.Fields' exists in both 'd:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET...
2
by: hsharsha | last post by:
Consider the below code: int main(void) { class inner {}; friend class inner; /* what does this signify???? */ return 0; }
31
by: Cesar Rodas | last post by:
Hello to all As far I know the unsigned char just use 1-byte, long 4-bytes... is this right??? Well I have the next code... #include <stdio.h> #include <stdlib.h>
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
6
by: Bint | last post by:
I'm getting this returned from a PHP script. What does this mean? <b>Parse error</b>: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in <b>/ho Thanks B
2
by: webinfinite | last post by:
Could anyone explain this snippet for me? #include <iostream> #include <vector> #include <algorithm> using namespace std; class PrintInt { public: void operator() (int elem) const {
5
by: brettcclark | last post by:
This define is from the Vista SDK from propidl.h: #ifdef __cplusplus #define REFPROPVARIANT const PROPVARIANT & #else #define REFPROPVARIANT const PROPVARIANT * __MIDL_CONST #endif
3
by: muddasirmunir | last post by:
I am trying to give the following Icon in my form in vb6. http://www.mediafire.com/?ymzgkgyi50j But , when I put this in my form I got error "Invalid Picutre" What wrong in it? How to add...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.