首页 > 其他分享 >数组元素移动到指定位置

数组元素移动到指定位置

时间:2023-01-14 11:55:06浏览次数:37  
标签:splice arr name temp 元素 指定 let 数组

let data=[{name:1},{name:2},{name:3}]

//arr:原数组,a:某个对象当前位置,b:某个对象想要移动到的位置
function Move(arr, a, b) {

let arr_temp = [].concat(arr);

arr_temp.splice(b, 0, arr_temp.splice(a, 1)[0]);

return arr_temp;

}

标签:splice,arr,name,temp,元素,指定,let,数组
From: https://www.cnblogs.com/yyy2020/p/17051522.html

相关文章