one in localstorage?
I want to make something like this :
if (the one in json == the one in localstorage) {
code here
} else {
code here
}
but im not sure how to write the one in json and the one in localstorage correctly.
Can someone help me ?
I think u can research about deep comparision in js...
stringify json data and compare with localStorage, only string values can be added to localStorage
function compare(a, b) { // swap if b has more keys to check them all if (Object.keys(b).length > Object.keys(a).length) { [ b, a ] = [ a, b ]; } for (key in a) { if (typeof a[key] === 'object') { if (!compare(a[key], b[key])) { return false } } if (a[key] !== b[key]) { return false; } } return true; }
Обсуждают сегодня