localStorage.getItem("test") - is holding some string value
I want to compare this value with array of objects - each of them stringified
If one of items in this array (newCombination) is the same as localStorage.getItem("test"), I want to return false.
It's not working, it's returning sometimes true, sometimes false. I hope it doesn't loop through whole array and stops if it's not true. I want it to loop though everything until it doesn't compare and it returns false - or true if it doesn't match anywhere.
function checkDuplicity(){
for (var i = 0; i < newCombination.length; i++) {
if(JSON.stringify(newCombination[i]) == localStorage.getItem("test")){
return false
}else{
return true
}
}
}
Example of what is in array of objects on positions 0-3 (from DevTool):
0: {movie: "Movie A", date: "2021-01-13", time: "10:00 am"}
1: {movie: "Movie A", date: "2021-01-14", time: "10:00 am"}
2: {movie: "Movie B", date: "2021-01-14", time: "10:00 am"}
3: {movie: "Movie C", date: "2021-01-14", time: "10:00 am"}
length: 4
__proto__: Array(0)