Last active
October 21, 2015 20:10
-
-
Save vparihar01/8db368678559a0940f6b to your computer and use it in GitHub Desktop.
to fetch all id with simple regex and then prepare the new link.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [] | |
var arrLinks | |
jQuery('a[id^=disabled_photo_thumb]').each(function(i,el) { console.log(arr << el.rel)}) | |
for(var i in arr){arrLinks.push("http://www.xyz.com/profile/xyz?profileid="+arr[i]+"&evt_ref=ZGFpbHk1")} | |
for(var i in arrLinks){ | |
var redirectWindow = window.open(arrLinks[i], '_blank'); | |
redirectWindow.location | |
} | |
Use a sequential for loop: | |
var myStringArray = ["Hello","World"]; | |
var arrayLength = myStringArray.length; | |
for (var i = 0; i < arrayLength; i++) { | |
alert(myStringArray[i]); | |
//Do something | |
} | |
@zipcodeman suggests the use of the for...in statement, but for iterating arrays for-in should be avoided, that statement is meant to enumerate object properties. | |
It shouldn't be used for array-like objects because: | |
The order of iteration is not guaranteed, the array indexes may not be visited in numeric order. | |
Inherited properties are also enumerated. | |
The second point is that it can give you a lot of problems, for example, if you extend the Array.prototype object to include a method there, that property will be also enumerated. | |
For example: | |
Array.prototype.foo = "foo!"; | |
var array = ['a', 'b', 'c']; | |
for (var i in array) { | |
alert(array[i]); | |
} | |
The above code will alert, "a", "b", "c" and "foo!". | |
That be particularly a problem if you use some library that relies heavily on native prototypes augmention (such as MooTools for example). | |
The for-in statement as I said before is there to enumerate object properties, for example: | |
var obj = { | |
"a": 1, | |
"b": 2, | |
"c": 3 | |
}; | |
for (var prop in obj) { | |
if (obj.hasOwnProperty(prop)) { | |
// or if (Object.prototype.hasOwnProperty.call(obj,prop)) for safety... | |
alert("prop: " + prop + " value: " + obj[prop]) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment