I write down the values ​​in this way:

//isEmpty - моя ф-ция, которая проверяет пустой ли объект //item - это обычный стринг if (isEmpty(JSON.parse(localStorage.getItem('todos')))) { localStorage.setItem('todos', JSON.stringify([item])); } else { var localTodos = JSON.parse(localStorage.getItem('todos')); localTodos.push(item); localStorage.setItem('todos', JSON.stringify(localTodos)); } 

Faced with the fact that you need to add the ability to delete some kind of record when you press a button. Those. if on an input I receive an array of a type

 todos: ['123', '12', '1'] 

and I need to delete the item with the index 1, it should turn out

 todos: ['123', '1'] 

I write the index to the value button and, when I click it, pull it out and try to delete the record in this way:

  //todoId - индекс элемента var todos = JSON.parse(localStorage.getItem('todos')); var newTodos = todos.splice(todoId, 1); localStorage.setItem('todos', JSON.stringify(newTodos)); 

But the output is some kind of beaverd and all records except the selected one are deleted. Can you tell me how you can do it differently?

    1 answer 1

    splice changes the array itself, and returns the deleted item

     var todos = JSON.parse(localStorage.getItem('todos')); todos.splice(todoId, 1); localStorage.setItem('todos', JSON.stringify(todos)); 
    • thanks, did not notice. on such nonsense stuck) - Bipa
    • js cunning and disgusting - Komdosh