localStorage.setItem('links', JSON.stringify([
{
id: 'foo',
name: 'FOO'
},
{
id: 'bar',
name: 'BAR'
}
]))
const data = localStorage.getItem('links')
const links = JSON.parse(data);
const result = {
name: 'FOOOOOOO',
id: 'foo',
score: 55
}
Object.assign(links.find(item => item.id === result.id), result)
console.log(
JSON.parse(localStorage.getItem('links'))[0]
) // Object { id: "foo", name: "FOO" }
localStorage.setItem('links', JSON.stringify(links))
console.log(
JSON.parse(localStorage.getItem('links'))[0]
) // Object { id: "foo", name: "FOOOOOOO", score: 55 }