<div id="1" brand="BMW" price="1000"></div>
<div id="2" brand="LEXUS" price="2000"></div>
<div id="3" brand="MERCEDES" price="3000"></div>
<div id="4" brand="VW" price="4000"></div>
<div id="5" brand="TESLA" price="5000"></div>
for (i=1;i<=5;i++) {
var brand = $('#'+i).attr('brand');
var price = $('#'+i).attr('price');
if (brand = 'LEXUS') {
for (b=1;b<=10;b++){
//code for doing things on specific model
}
}
if (price = "4000") {
for (c=1;c<=20;c++) {
//code for doing things on specific price
}
}
}
On the original code I have more than 5 nested loops on many places and I am looking for a proper way to replace this. If possible to not use loops at all.
I have tried array object and mapping doesn’t really helped me much as I still need to use for loops to get data from specific div id. I want to possibly use zero loops for this approach.