<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>将一个数组push到另一个数组中去</title>
</head>
<body>
<script>
/*
将arr1数组里面的值复制到arr数组里面,
生成一个新的数组。['apple', 'banana', 'pear']
*/
const arr= ['apple', 'banana', 'pear','orange', 'maongo'];
const arr1= ['orange', 'maongo'];
// //你可能会使用:push()方法
// arr.push(arr1);
// console.log(fruit)//(6) ["apple", "banana", "pear", "orange", "maongo", Array(2)]
// //当你使用push()方法的时候你发现,并没有我们想的形式,这个时候我们需要apply()方法
// arr.push.apply(arr,arr1);
// console.log(fruit)//(7) ["apple", "banana", "pear", "orange", "maongo", "orange", "maongo"]
//其实没有必要这么麻烦,直接用...就可以替代apply()方法
// ... 是ES6的语法 解析的意思
arr.push(...arr1);
console.log(arr)//(7) ["apple", "banana", "pear", "orange", "maongo", "orange", "maongo"]
</script>
</body>