If he’s just looking to see if the domain ‘www.emp-online.it’ is in there, it can be achieved more simply with:
var domain = 'www.emp-online.it',
urls = [
'http://www.emp-online.it/bin/shop.php?prog=shop&funktion=PRODUCTINFO&article=670017',
'http://www.masteringapi.com/tutorials/how-to-check',
'http://facebook.stackoverflow.com/questions/3548493/how-to-',
'http://www.emp-online.it/art_670017/'
],
i;
for (i = 0; i < urls.length; i += 1) {
if (urls[i]).search(domain) > -1) {
console.log(urls[i]);
}
}
As a separate issue, declaring variables within the for loop does not restrict them to there. JavaScript does not have block scope. There is only function scope that currently applies to JavaScript. This means that wherever a variable is declared, that declaration is automatically hoisted to the top of the function.
Because it can be confusing for what you have written to differ from what actually occurs, it’s a best-practice to declare all of the variables from one var statement right at the start of the function that they are in. In this case you have no functions, so it’s just right at the start instead.
Caching the loop length also does not provide any significant improvement, but if you were to do it then it could be done in the following manner:
var ...,
i,
urlsLen = urls.length;
for (i = 0; i < urlsLen; i += 1) {
...
}
It means that if you need a loop to increase by 2, or by some other value (returned from a function perhaps) then the i += 1 version is easier and more consistent to modify.
The other reason that I have for staying away from ++ is that it doesn’t improve, the code or make it faster, or easier to understand, or to modify. So, since ++ provides no realistic benefit - I consider it to to not be a useful part of JavaScript.
It’s not directly harmful, but it does have the potential to harm when used in other places instead of clearer techniques.
So my personal standard is to not use ++, which also prevents me from being tempted use it in other parts of the code in potentially confusing ways.