0
$(function(){
    $('body').on('click', '.queue', function(event) {
        var video = $(this).closest('.video');
        console.log(video);
        var queue = localStorage.getItem('queue');
        if (! queue ) {
            queue = [];
        }
        queue.push(video);
        localStorage.setItem('queue', queue);
        console.log(localStorage.getItem('queue'));
        bootstrap_alert.success('queued!');
    });
});

when I try to test this, I get the error on console saying

TypeError: queue.push is not a function 

queue.push(video);

What is that I am doing wrong here?

daydreamer
  • 87,243
  • 191
  • 450
  • 722
  • 1
    check the type of queue with `console.log(queue.constructor.toString())` – Hersheezy Aug 14 '12 at 22:51
  • 1
    possible duplicate of [how to store an Array in localStorage?](http://stackoverflow.com/questions/3357553/how-to-store-an-array-in-localstorage) and [Storing Objects in HTML5 localStorage](http://stackoverflow.com/q/2010892/218196). – Felix Kling Aug 14 '12 at 22:57

1 Answers1

6
var queue = localStorage.getItem('queue');

localStorage doesn't store (or return) arrays. Therefore, queue is not an array.

ahren
  • 16,803
  • 5
  • 50
  • 70