编辑
核心代码
<!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>添加元素</title> </head> <body> <!-- 在数组 arr 开头添加元素 item。不要直接修改数组 arr,结果返回新的数组 --> <script>function prepend(arr, item) { return [item].concat(arr) } </script> </body> </html>
总结
直接concat当前数组连接即可 没有多余操作