Reputation: 449
I have an array which is called dataid and here is the console.log
of my array:
I want to make it so if I click on a span with the id "next", it send me in my URL the value of the next id in my array datatid. So first we need to determine the position of myid in my array and then determine which value is the next to send it in my URL.
This is what i tried:
var newid = GetURLParameter('myid');
console.log(newid);
var dataid = localStorage.getItem("mesid");
console.log(dataid);
function nextticket(){
var position = dataid.indexOf(newid)+1;
console.log(dataid.indexOf(newid));
console.log(position);
}
But the position are wrong!
Upvotes: 0
Views: 61
Reputation: 6185
localStorage stores strings, not arrays. The position 10 in your output is because "4653" occurs at character position 10 in the string "5475,4831,4653,...".
You will need to split the string back into an array with something like this:
var position = dataid.split(',').indexOf(newid) + 1;
where the split()
method as used here converts a comma-delimited string into an array.
Upvotes: 2