Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Retrieve all the values stored in array of local storage

javascript html5

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 ashirogimuto

ashirogimuto

    CC Lurker

  • Just Joined
  • Pip
  • 1 posts

Posted 28 May 2016 - 10:19 AM

I am storing values in array and then storing the array in local storage. While retrieving the values in the same function I am getting all the values but when I retrieve them outside the function I only get the last pushed value in the array. How can I get all the values in the array of local storage outside the function?

Code:

storeGrabID(10);
	storeGrabID(7);
	storeGrabID(9);
	storeGrabID(4);
	function storeGrabID(id)
	{
		var list = new Array();	
		list.push(id);
		localStorage.setItem('offerID',JSON.stringify(list));
		console.log(localStorage.getItem('offerID'));//getting all the values 
	}
	var storedId = JSON.parse(localStorage.getItem('offerID'));
	console.log(storedId);//getting only last pushed value i.e. 4