I'm sorry, I don't specifically understand that code so I am having trouble implementing it. Using the code you last provided, does that automatically add a new item to my object? It didn't seem to add it to shottolist, but it essentially needs to make it to shotprelist but I believe I can do that manually unless this code is just supposed to update it.
My plan was to run the code that follows the code you last provided only if the new item is unique. I'm sorry, I don't really know how to explain this and make it make sense. But does your code add to the object, or does it return a true/false depending on if it unique? And how do I access that true/false because I wan't able to access it with console.log.
pre
//existing object
var unique = localStorage.getItem('shottolist');
//potential new item
var arr = {shot: "ss", dose: "33"};
//var unique = [];
for (var i = 0; i < arr.length; i++) {
var isUnique = true;
for (var j = 0; j < unique.length; j++) {
if (arr.shot === unique[j].shot || arr.dose === unique[j].dose){
isUnique = false;
}
Code: Select all
}
if (isUnique) {
unique.push(a[i]);
}
}
//lines 21-35 add the new item to the front of the list so that when I limit, the oldest item is removed
var pre = localStorage.getItem('shotprelist')
var pre2 = pre.substring(
pre.lastIndexOf("[") + 1,
pre.lastIndexOf("]")
);
var current = localStorage.getItem('shottolist')
var current2 = current.substring(
current.lastIndexOf("[") + 1,
current.lastIndexOf("]")
);
var post = "[" + pre2 + "," + current2 + "]";
//limits items
var limitObject = post && post.length ?
Code: Select all
JSON.parse(post).slice(0, 5) : [];
var limit = JSON.stringify(limitObject);
localStorage.setItem("shottolist", limit);
/pre