I have a code with too many if conditions. So, I want to convert this code to foreach loop but somehow it's not working.
if (str_array[0] === "1" || str_array[1] === "1" || str_array[2] === "1" || str_array[3] === "1" || str_array[4] === "1" || str_array[5] === "1" || str_array[6] === "1" || str_array[7] === "1" || str_array[8] === "1" || str_array[9] === "1" || str_array[10] === "1" || str_array[11] === "1") {
column_data[0].hidden = false;
}
if (str_array[0] === "2" || str_array[1] === "2" || str_array[2] === "2" || str_array[3] === "2" || str_array[4] === "2" || str_array[5] === "2" || str_array[6] === "2" || str_array[7] === "2" || str_array[8] === "2" || str_array[9] === "2" || str_array[10] === "2" || str_array[11] === "2") {
column_data[1].hidden = false;
}
I have total 12 if statements with or condition.
for (var i = 1; i <= 12; i++) {
console.log('"' + i + '"');
if (str_array[0] === '"' + i + '"' || str_array[1] === '"' + i + '"' || str_array[2] === '"' + i + '"' || str_array[3] === '"' + i + '"' || str_array[4] === '"' + i + '"' || str_array[5] === '"' + i + '"' || str_array[6] === '"' + i + '"' || str_array[7] === '"' + i + '"' || str_array[8] === '"' + i + '"' || str_array[9] === '"' + i + '"' || str_array[10] === '"' + i + '"' || str_array[11] === '"' + i + '"') {
console.log(i - 1);
column_data[i - 1].hidden = false;
}
}
Loop is executing properly and I got value. "1","2","3","4","5" etc. in console.log('"'+i+'"');.
But somehow it's not working. It's working with static code but when I put it in loop it's not working. Is there any difference in qoutes values which I'm getting in for loop and static.