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.
    – user3310334
    CommentedSep 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 

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.