WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Associative Arrays, Jose Luis Martinez, June 22, 2004
     Re:Associative Arrays, Erik Arvidsson, July 19, 2004
     Re:Associative Arrays, Jude, July 11, 2004
         Re:Associative Arrays, Erik Arvidsson, July 19, 2004

Subject: Re:Associative Arrays From: Jude Date: July 11, 2004

Maybe not such a good idea to use dictionary objects, as you are immediately limiting yourself to IE. Moreover, what is commonly known as an "associative array" in Javscript is in fact a plain object. There is no need to create an array. If you stick with the Javascript object, then you can rely on it's inherent flexibility.

The easiest way to 'write' one is to use literal notation:

var tel =
{
    jose: '333555666',
    andy: '555666777', 
    'function':'56454845'
}

I have given you a friend called function, to demonstrate that if you need to use an identifier (property name) that is a JS reserved word, that all you need to do is quote it. If in doubt, quote.

To can get all names/numbers using a for..in loop, and you can test for membership like so:

var isInBook = tel["fred"]


 




Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX