Hello Katya,
No errors...in console...If you just guide me on how to correctly use the above code (to delete items from the ARRAY)...I have tried different ways with no luck...
Thanks =)
Hello Katya,
No errors...in console...If you just guide me on how to correctly use the above code (to delete items from the ARRAY)...I have tried different ways with no luck...
Thanks =)
Hello! Could you clarify what do you send in itemValue? For example to delete first value from screen what would you send "a" or "52d9a36..."?
hello Maryna,
I have tried with both:
removeArrayItem('favorites',Appery('negocioo').text());
removeArrayItem('favorites',Appery('idd').text());
but none does anything...no one item is delete from the array...
Let's say you delete with nombre_negocio value. Replace your functions to the following prefunction myload(varName) {
var arr;
try {
arr = JSON.parse(localStorage.getItem(varName));
if ({}.toString.call(arr) !== "[object Array]") {
arr = [];
}
} catch ( e ) {
arr = [];
}
return arr;
}
function save(item, varName) {
var arr = myload(varName);
arr.push(item);
localStorage.setItem(varName, JSON.stringify(arr));
}
function removeArrayItem(varName, itemValue) {
var arr = myload(varName), i, len;
for (i = 0, len = arr.length; i < len; i++) {
if (arr['nombre_negocio'] === itemValue) {
arr.splice(i, 1);
break;
}
}
localStorage.setItem(varName, JSON.stringify(arr));
}/pre
Thanks Maryna, it works fine!!!
I just need to work on swaping both icons at button click, in order to avoid user add to favorites the same item several times...If I have trouble hope you could help!
=)