'Can't save more than 10 object in localStorage
I have very specific problem. Can't save more than 10 object in localStorage.
To object key 10 javascript code works great but when 10th object saved in localStorage can't save 11th object.
11th object just overwriting 10th object.
Here is my code:
// save in localStorage
ht.addEventListener(
"click",
function (e) {
e.stopPropagation();
let nl = localStorage,
keys = Object.keys(localStorage).sort(),
mtch = false,
ns = {
link: f[i].link,
source: f[i].pubDate + " - " + f[i].source,
title: f[i].title,
description: f[i].description,
};
//console.log(keys)
if (nl.length > 0) {
for (let n = 0; n < nl.length; ++n) {
if (JSON.parse(nl[keys[n]]).link == f[i].link) {
mtch = true;
}
}
// if info is unique
if (!mtch) {
let key = parseInt(keys.pop()) + 1;
console.log(key, "a");
localStorage.setItem(key, JSON.stringify(ns));
}
} else {
localStorage.setItem(0, JSON.stringify(ns));
}
},
{ passive: true }
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
