Is it possible to work with associative arrays multiple times?

var arr[key]; 

Where key is an array of large numbers (for example, {1234, 33412, 31235, 554235}).

I do not know how to get the values, except how to use the for loop. Because of the empty values ​​of the array, the script does not work through speed ?!

  • I'm not sure that you can use an array as a key. Convert this array to a string, so it is guaranteed to be a key. But the task itself is somehow strange. Reformulate. - KoVadim

2 answers 2

What do you mean by multiple jobs? There are no associative arrays in JavaScript; there are just arrays and objects that behave like associative arrays. If just arrays with a length pass, then it will squeeze. And if objects are like associative arrays, then the cycle should be appropriate:

 var a = { 123:"cat", 65555:"dog" }; for(var property in a) { console.log(a[property]); } 

    I do not understand the question.

    If you need to get an element at a specific index, for example, 31235 , then arr[2];

    And you can also use the key to the index var arr = {a : 1234, b : 33412, c : 31235, d : 554235} where arr.c is 31235 .

    And if you need to find an index that corresponds to this number, then you cannot do without for

     var arr = [1234, 33412, 31235, 554235]; for(i in arr) { if(arr[i] == 31235) { alert("found. iterator is: "+ i); } }