Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test localStorage key ordering
<html>
<body>
<pre id="output"></pre>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="index.js"></script>
</body>
</html>
localStorage.setItem('3', '3');
localStorage.setItem('2', '2');
localStorage.setItem('1', '1');
localStorage.setItem('10', '10');
localStorage.setItem('0', '0');
localStorage.setItem('2', '2');
localStorage.setItem('100', '100');
var i = -1;
var len = window.localStorage.length;
while (++i < len) {
var key = window.localStorage.key(i);
console.log(key);
$('#output').text($('#output').text() + '\n' + key);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment