I am currently considering the best approach to loop through an array in my code before proceeding further. I have some concerns about the link (var link = ... ) and the if statement.
Is this the most optimal way to iterate over array1 and compare the values to those in array2? If my code is correct (which I am unsure of at the moment), is there a more efficient way to achieve this?
Furthermore, I am curious whether this loop will run through every element of array1 indefinitely or just one of them indefinitely.
var array1 = [741, 451, 54188, 5847, 5418, 54944, 310, 541, 7451, 10211, 113, 9115, 62, 2841, 52482481, 24];
var array2 = [15, 418, 488, 130000, 8482, 55, 16, 14, 2546, 651, 4521, 11, 54, 659, 542, 1152];
var myObj = {};
array1.forEach(function(item, i) {
myObj[item] = array2[i];
});
var Loop = setInterval(function(){
for (var prop in array1) {
var link = "http://blahblahblah.com/blah/" + array1[prop] + "/blahblah"
$.get(link,function(data){
var dataGiven = $("span.cost-in-usd:first-child").text();
dataGiven = Number(dataGiven.replace(",",""));
dataGiven = Number(dataGiven.replace("(",""));
dataGiven = Number(dataGiven.replace(")",""));
if (dataGiven <= myObj[prop]) {
//stuff happens
}
});
}
},0)