Reputation: 830
I have an application in which i am storing values in localstorage. By default my first value is null due to which i am getting error to run the code so i want to remove the first element and continue the processes. can anyone please help me how to remove first element from list?
Piece of my code is below:
var str = localStorage.getItem("appidlist");
var mySplitResult = str.split(",");
for(var i = 0; i < mySplitResult.length; i++) {
if (.....) {
.
.
}
}
where str returns null,1,2,3,..... I hope my question is clear can anybody help me.
Upvotes: 1
Views: 137
Reputation: 72857
This should do the trick:
var str = localStorage.getItem("appidlist");
var mySplitResult = str.split(",").splice(1); // Remove the first item.
for(var i = 0; i < mySplitResult.length; i++) {
// Stuff
}
Upvotes: 0
Reputation: 2731
Instead of uing the shift()
function, I would suggest you to create a function that return a new clean array. This will solve even the case where there are more than one (and in any postion) null
value.
Upvotes: 0
Reputation: 128
This should also work:
var str = localStorage.getItem("appidlist");
var mySplitResult = str.split(",");
mySplitResult.splice(0, 1);
Upvotes: 1