Don't make function within a loop

Hi

Was trying this :

// basses, bois, cordes, cuivres are all arrays
var indexPistes = [basses,bois,cordes,cuivres,...]
var Pistes = ['Pistes_Basses_','Pistes_Bois_','Pistes_Cordes_','Pistes_Cuivres_',...]

var distrib_id_bois = Array(indexPistes[1].length).fill(0).map((el,i)=> Pistes[1]+indexPistes[1][i])

Returns what i expected :

Pistes_Bois_7,Pistes_Bois_8,Pistes_Bois_9,Pistes_Bois_10,Pistes_Bois_11

But trying this to automate the process :

for(var i = 0 ; i < indexPistes.length ; i++) {var distrib_id = Array(indexPistes[i].length).fill(0).map((el,ind)=> Pistes[i]+indexPistes[i][ind])}

Returns a warning : Don't make a function within a loop

So... how can i do to automate the process of adding a string taken in the array 'Pistes', to the values of another array in an array (indexPistes) ??...

Thank you

Well it's only a warning so it should work. To avoid it you could simply declare the function passed to map() outside of the loop:

function mapping(el, ind) {
  return Pistes[i]+indexPistes[i][ind]
}
for (...) {
  Array(...).map(mapping)
}