1:ES6扩展运算符、合并多个数组
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>test</title> <link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> </head> <body> </body> <script> let arr1 = [0, 1, 3]; let arr2 = ["a", "b", "c"]; let arr3 = ["e", "f", "g"]; let arr = [...arr1, ...arr2, ...arr3]; console.log(arr) </script> </html>
2:concat方法、合并多个数组
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>test</title> <link rel="stylesheet" href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> </head> <body> </body> <script> let arr1 = [0, 1, 3]; let arr2 = ["a", "b", "c"]; let arr3 = ["e", "f", "g", "d"]; //let arr = [...arr1, ...arr2, ...arr3]; let arr = arr1.concat(arr2, arr3); console.log(arr) </script> </html>