我想在JS中合并两个数组,然后对它们进行排序。以下代码将在页面上输出两个数组,但仅在我删除“newArr.sort();”时才会输出线。否则,我一无所获。谁能在这里帮助新手?
function merge(arr1, arr2){
var arr1 = [1,21,13,24,15];
var arr2 = [16,7,81,59,14];
var newArr = "[ ]";
arr1.sort();
arr2.sort();
newArr = arr1+","+arr2;
newArr.sort();
document.writeln(newArr);
}
答案 0 :(得分:1)
var arr1 = [1,21,13,24,15];
var arr2 = [16,7,81,59,14];
var arr3 = arr1.concat(arr2);
alert(arr3);
Jsfiddle:http://jsfiddle.net/ZRLSs/