1.要求不改变原数组,要么用临时数组缓存拿临时数组操作,要么利用数组的原生方法,比如filter就是不改变原数组
2.相当于从中间切一刀,然后返回被切开之后的数组,返回的数组少掉index的这个元素。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS8 数组排序 </title>
</head>
<body>
<script>
const _delete = (array,index) => {
// 补全代码
// 利用es6 ... 的新特性,缓存数组
let temp=[...array];
console.log( temp.slice(0,index) );
// slice() 方法以新的数组对象,返回数组中被选中的元素。
//slice() 方法选择从给定的 start 参数开始的元素,并在给定的 end 参数处结束,但不包括。
//concat() 方法用于连接两个或多个数组。
//concat() 方法不会更改现有数组,而是返回一个新数组,其中包含已连接数组的值。
return temp.slice(0,index).concat( temp.slice(index+1,temp.length) );
}
let test=[1,2,3,4,5,6,7];
console.log( _delete(test,3) );
</script>
</body>
</html>