Let’s say I have this javascript object array,
[{a:'a', b:2, c:true}, {a:'b', b:3, c:true}, {a:'a1', b:3, false}]
Let’s say I need to move the object at index 0 to 2. I have tried this function with no luck.
Array.prototype.move = function (old_index, new_index) {
if (new_index >= this.length) {
var k = new_index - this.length;
while ((k--) + 1) {
this.push(undefined);
}
}
this.splice(new_index, 0, this.splice(old_index, 1)[0]);
};
The object array is not correct, it needs the ‘c’ variable in the last item:
Working example:
http://jsfiddle.net/WgLKc/1/