I’m pretty new to jQuery/JS. But I have loop in jQuery where I would like to do some checks. I would like to check if the URL has already printed or not. The data for the loop comes from JSON if that matters.
Basically I would have a array var = myArray where I would put all the URLs from the loop. I go through that loop with each. Then each time I would check if the URL is already in array. As a pseudo:
var myArray = [];
each data {
myArray.push({'url':data.url});
if data.url is already in myArray {
do stuff
}
if data.url is not already in myArray {
do other stuff
}
}
I was playing aounrd with jQuery.inArray() but I always got -1
Thank you for your help!
In your pseudo code you were pushing to the array before you check if it existed, so that it would always be there. That and you need to push
data.urlinstead of{'url':data.url}Working example of what you are looking for: