so I've retrieved an object containing photos from facebook, Which all works perfectly fine.
for (var i = 0; i < photoLikes.data.length; i++) {
if (photoLikes.data[i].name === facebook.username) {
alert("You have already liked this photo. Unliked");
var count = photoLikes.data.length;
//facebook.unlikePhoto(id, count);
}
^^ this code works above,
BUT the issue is when seeing if the name ISNT in the array, what it does is it iterates over every item and if it isnt equal to the username (searching if username is in the object) calls the else statement.
I just need it to be called once. anyone have any idea? this is my statement for not in. I've tried this:
for (var x = 0; x < photoLikes.data.length; x++) {
if (facebook.photos.indexOf(facebook.username == -1)) {
console.log("increment");
}
}
and
for (var x = 0; x < photoLikes.data.length; x++) {
if (photoLikes.data[i].name != facebook.username) {
console.log("increment");
}
}
and both trigger every time.
Thanks
edit: I'm trying to break out of the for loop once the if condition is met.