0

I have an array like so:

var data = {"result":"success","ids":["00000","54321","123","22222","11111","55555","33333","abc123","123abc","12345","44444"]}
localStorage.ids = data.ids;

But now when I do:

angular.forEach(localStorage.ids, function(id, key) {
    console.log(id);
});

I get like:

0
0
0
0
0
,
5
4
3   

And so on.

When I console.log(JSON.stringify(localStorage.ids)); I get:

"00000,54321,123,22222,11111,55555,33333,abc123,123abc,12345,44444"

Does anyone know why this would happen?

1
  • It looks to me like either some code you've omitted is stingifying localStorage.ids before the forEach loop, or angular's forEach doesn't work as expected. Commented Sep 4, 2016 at 18:11

1 Answer 1

1

localStorage stores only strings.

localStorage.setItem('ids', JSON.stringify(data.ids)); // to save

var ids = JSON.parse(localStorage.getItem('ids')); // to get
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.