Cattle customer network front-end programming: Merging arrays and array arr1 arr2. Do not directly modify the array arr, the result returns a new array

There are many ways, but a few thoughts on:

1, the two characters are directly connected

2, a first array of characters to A, then the character is assigned to another array A

This article provides only a few reference method:

//方法一:使用concat
        function concat(arr1, arr2) {
            // var arr = [];
            // arr = arr.concat(arr1);
            // arr = arr.concat(arr2);
            // return arr;

            return arr1.concat(arr2);
        }
//方法二:slice+concat
        function concat1(arr1, arr2) {
            var arr = arr1.slice(0);
            arr = arr.concat(arr2);
            return arr;
        }
//方法三:slice+push.apply
        function concat2(arr1, arr2){
            var arr = arr1.slice(0);
            [].push.apply(arr,arr2);
            return arr;
        }

Of course, there are the ordinary cycle assignment, I do not write here

Guess you like

Origin www.cnblogs.com/purple-windbells/p/11249491.html
Arr