Click here to Skip to main content
15,912,507 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can i have a javascript array in the following fashion.
If yes how can i access it


C#
var mycars = new Array();
mycars['page1'][0] = new Array( "5.00", "5 items", "red" );
mycars['page1'][1]= new Array( "6.00", "6 items", "ed" );
mycars['page1'][2]= new Array( "7.00", "7 items", "d"
Posted

No, you can't have an array accessed by strings, that would be a dictionary, which I don't think js has. A 2D array, however, is fine.
 
Share this answer
 
Comments
gaurish thakkar 30-Jul-12 3:39am    
mycars[0] = ["5.00", "5 items", "red"];
mycars[1] = ["6.00", "6 items", "ed"];

using this notation how can i search for a perticular element
Christian Graus 30-Jul-12 3:42am    
mycars[0][0] is "5.00". mycars[0][1] is "5 items".
gaurish thakkar 30-Jul-12 8:44am    
GOt it thanks :)
you can do it in the following way....
JavaScript
var mycars = new Array();
            mycars[0] = ["5.00", "5 items", "red"];
            mycars[1] = ["6.00", "6 items", "ed"];
            alert(mycars[0][2]);
 
Share this answer
 
v2
using two loops you can go througth the 2d array and find the element that meets your condition.

C#
var xlength = mycars.length;
var ylength = mycars[0].length;



you can use the length of both dimensions using above code....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900