I have an array of objects and I want to swap the position of two elements in the array. I tried this:
var tempObject = array.splice(index, 1, array[index + 1]);
array.splice(index+1, 1, tempObject);
But it doesn't seem to work properly as it results in some weird errors. For example, I am unable to use methods of the object. Calling array[x].getName
results in an error.
Can any body lend a helping hand here?
Just in case it is important, I have used object.prototype
to add the methods.