Call arrangements within a cycle

0

What I would like to be able to send to call some arrangements and go through each of them in Javascript in a dynamic way.

For example:

var idarray=[1,5,8]    
var arreglo1=[23,34,56,45,534]
var arreglo5=[34,34,12,65]
var arreglo8=[34.23.65.87]

I have "n" number of arrangements that have the same name but only change the number

  

fix 1

I have these numbers in another array, so what I want is to cycle through each cycle to call each one of the arrangements and go through its elements.

Thanks

    
asked by Jess182 16.05.2018 в 02:48
source

3 answers

1

Here is the solution

var idarray=[1,5,8];
var arreglo1=[23,34,56,45,534];
var arreglo5=[34,34,12,65];
var arreglo8=[34,23,65,87];

for(var i = 0; i < idarray.length; i++){
    var array = window["arreglo"+idarray[i]]; //llamo a la variable arreglo que tenga el numero del array idarray 
    console.log("arreglo"+idarray[i]);

    for(var j = 0; j < array.length; j++){ //recorro cada valor de dicho array
        console.log(array[j])
    }
}
    
answered by 16.05.2018 в 03:13
0

You have to go through the array of the names of your array and with the help of the window send them to call.

        <script>
  var idarray=[1,5]    
  var arreglo1=[23,34,56,45,534]
  var arreglo5=[34,34,12,65]

  for (x=0;x<idarray.length;x++){
    alert( window['arreglo' + idarray[x]]);
  }

  </script>
    
answered by 16.05.2018 в 02:58
0

var idarray=[1,5];    
var arreglo1=[23,34,56,45,534];
var arreglo5=[34,34,12,65];

for (i in idarray){
    var arrActual = window['arreglo' + idarray[i]];
    console.log("Arreglo "+ idarray[i]);
    for(x in arrActual){
      console.log("Valor " + arrActual[x] + " del array " + idarray[i]);
    }
}

I hope you serve

    
answered by 16.05.2018 в 03:31