468,301 Members | 1,477 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,301 developers. It's quick & easy.

An array within another array

Can we store an array within another array in javascript

Expand|Select|Wrap|Line Numbers
  1. var locat = new Array();
  2. var element = new Array();
  3. locat[] = element;
or Can we use like this
Expand|Select|Wrap|Line Numbers
  1. locat['name'][0] = "manoj";
  2. locat['address'][1] =  "Noida";
Please let me know the possible way
Jan 7 '09 #1
9 1624
213 Expert 100+
Yes you can, but not the way you want, associative arrays doesn't exist in javascript, what you need is an array with objects inside.
I also recommend you the json syntax, is easier and cleaner.

Something like this:
Expand|Select|Wrap|Line Numbers
  1. var locat = [
  2.     {'name':'manoj', 'address':'Noida'},
  3.     {'name':'some other name', 'address':'some other address'},
  4.     {'name':'etc...', 'address':'etc...'}
  5. ];
  7. alert( locat[0].name ); //this will alert "manoj"
  8. alert( locat[1].address ); //this will alert "some other address"
Jan 7 '09 #2
8,651 Expert Mod 8TB
you don't need the quotation marks around the property names.
Expand|Select|Wrap|Line Numbers
  1. var locat = [
  2.     {name:'manoj', address:'Noida'},
  3. // ...
  4. ];
if you have many objects to insert, maybe consider using a constructor function.

Jan 7 '09 #3
213 Expert 100+

You don't needed but it's reccomended, to reduce the load on the js engine, and semantically, anything without quotes in js tries to be parsed as a variable, that's why if you quote it, you avoid making the engine
do an extra unnecessary check.
Anyways, it's not like it will make the script crash if you don't use them ;)
I just use them whenever I feel so
Jan 7 '09 #4
rnd me
427 Expert 256MB
he was talking about JSON though, in which case you would.

double quotes too, not single quotes.
Jan 7 '09 #5
8,651 Expert Mod 8TB
I don't know if Javascript will try to read it as object literal or JSON in the first place, thus the remark.
Jan 7 '09 #6
I have a web application , now I want to have IVR implementation , I will be using IVR which is a third party with my application.
Please guide me how should I start to integrate IVR with my application as my application will interac with my database.
Will I be rading and writing the response to the third party(IVR) ?
Mar 9 '09 #7
5,390 Expert Mod 4TB
are you talking about something like this?
Mar 9 '09 #8
when we create index on tables , do the indexes gets cached or not by default.
Or we have to manually LOAD THE INDEXES INTO THE CACHE
Mar 14 '09 #9
5,390 Expert Mod 4TB
please specify your question more clearly ... i guess! that you mean database-tables and in case you do you should post in the appropriate forum since this ... the current forum where you have posted it ... is the JavaScript-forum and doesn't deal with such kind of questions ...

kind regards,
Mar 14 '09 #10

Post your reply

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

Similar topics

reply views Thread by WebRod | last post: by
2 posts views Thread by Chris Haynes | last post: by
4 posts views Thread by Eric A. Johnson | last post: by
104 posts views Thread by Leszek | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.