Hello I have a piece of code that checks a value against an array and if that value is not found in the array, then it adds that value to another array (called the soldListingArray
). It then saves the soldListingArray
to the localStorage (using localStorage.setItem("array", soldListingArray
). For some reason, in my console
I can see that the variable is the correct one, after adding it to the array, but outside of the code when I call for the entire array, it says it's empty.
array1
is the array I'm checking all the values inside against the array2
array.
Here is my code:
function checkToSeeIfListingIsSold() {
var soldListingArray = localStorage.getItem("array");
var x = 0;
var y = array1.length;
do {
var index = array1[x];
if (array2.indexOf(index) == -1) {
// Here I add the variable to my soldListingArray
soldListingArray[soldListingArray.length] = index;
// Here my console says what has been added to the soldListingArray (the value is correct).
console.value += index + " has been added to soldListingArray;\n";
}
x++;
} while (x < y)
localStorage.setItem("array", soldListingArray);
// Here I ask my console to display my soldListingArray but I get an empty array back.
console.value += "Sold Array: " + soldListingArray;
}
Why wasn't the index
variable added and saved to my soldListingArray
?
Any help is appreciated! Thanks in advance.