想想看,我有如下一個對象數組:更改對象數組的順序
var array = [
{ name: "A", position: "0" },
{ name: "B", position: "1" },
{ name: "C", position: "2" },
{ name: "D", position: "3" },
{ name: "E", position: "4" },
{ name: "F", position: "5" }
];
比方說,用戶拖動有4位的元素,把它有位置1
var replacedItem = { name: "E", position: "4" };
var destinationItem = { name: "B", position: "1" };
的元素
如何可以重新排列使用javascript具有包含下列值的陣列元素的位置:
var array = [
{ name: "A", position: "0" },
{ name: "E", position: "1" },
{ name: "B", position: "2" },
{ name: "C", position: "3" },
{ name: "D", position: "4" },
{ name: "F", position: "5" }
];
個謝謝,
不應該B獲得位置4? – 2014-08-29 08:09:52
你應該看看array.splice,這可以重新排列 – AirBorne04 2014-08-29 08:11:49