By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,078 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,078 IT Pros & Developers. It's quick & easy.

An array within another array

P: 5
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;
  4.  
or Can we use like this
Expand|Select|Wrap|Line Numbers
  1. locat['name'][0] = "manoj";
  2. locat['address'][1] =  "Noida";
  3.  
Please let me know the possible way
Jan 7 '09 #1
Share this Question
Share on Google+
9 Replies


xNephilimx
Expert 100+
P: 213
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. ];
  6.  
  7. alert( locat[0].name ); //this will alert "manoj"
  8. alert( locat[1].address ); //this will alert "some other address"
  9.  
Jan 7 '09 #2

Dormilich
Expert Mod 5K+
P: 8,639
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.

regards
Jan 7 '09 #3

xNephilimx
Expert 100+
P: 213
@Dormilich

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
Expert 100+
P: 427
@Dormilich
he was talking about JSON though, in which case you would.

double quotes too, not single quotes.
Jan 7 '09 #5

Dormilich
Expert Mod 5K+
P: 8,639
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

P: 5
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

gits
Expert Mod 5K+
P: 5,371
are you talking about something like this?
Mar 9 '09 #8

P: 5
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

gits
Expert Mod 5K+
P: 5,371
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,
MOD
Mar 14 '09 #10

Post your reply

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