Reordering arrays

Posted by Wurlitzer on Stack Overflow See other posts from Stack Overflow or by Wurlitzer
Published on 2010-03-14T00:31:03Z Indexed on 2010/03/14 0:35 UTC
Read the original article Hit count: 387

Filed under:

Hi,

Say, I have an array that looks like this:

var playlist = [
    {artist:"Herbie Hancock", title:"Thrust"},
    {artist:"Lalo Schifrin", title:"Shifting Gears"},
    {artist:"Faze-O", title:"Riding High"}
];

How can move an element to another position?

I want to move for example, {artist:"Lalo Schifrin", title:"Shifting Gears"} to the end.


I tried using splice, like this:

var tmp = playlist.splice(2,1);
playlist.splice(2,0,tmp);

But it doesn't work.

Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about JavaScript