不删除localstorage

时间:2016-11-30 09:55:14

标签: javascript local-storage

为什么会这样?我需要删除2个键,但只删除1个键

<script>
localStorage.setItem('2', 'lalala')
localStorage.setItem('3', 'lalala')

for (var i = 0 ; i < localStorage.length; i++){
if (localStorage.key(i) > 1)
{
alert (localStorage.key(i)) //show 2 time
localStorage.removeItem(localStorage.key(i)) //remove 1 time (remove 1 key)
}
</script>

0 个答案:

没有答案