[Solved] For-each in a array Javascript [duplicate]


You can try the following below code.

var rank1 = 0
var rank2 = 0
var rank3 = 0
var rank4 = 0

const array1 = ['rank1','rank1','rank1','rank3']

array1.forEach( function( item, i ) {
  
  eval( item + '+= ' + 1 + ';');
  
} );

console.log(rank1, rank3);

2

solved For-each in a array Javascript [duplicate]