常用js 数组

<script type="text/javascript">
//JavaScript Array(数组)对象

var arr = new Array(6)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
arr[3] = "James"
arr[4] = "Adrew"
arr[5] = "Martin"
var arrInt = new Array(6)
arrInt[0] = "10"
arrInt[1] = "5"
arrInt[2] = "40"
arrInt[3] = "25"
arrInt[4] = "1000"
arrInt[5] = "1"
var arrInt2 = new Array(4,7,2,8,5,8,9,2,1)
var arr1 = new Array('James', 'Wade', 'Kebe');
var arr2 = new Array('Bosh', 'hahah', 'Kebe');

//1.合并两个数组 - concat()
document.writeln( "合并两个数组:"+arr1.concat(arr2) + "<br><br>");

//2.用数组的元素组成字符串 - join()
document.writeln("数组的元素组成字符串(','隔开):"+arr1.join() + "<br><br>");
document.writeln("数组的元素组成字符串('&'隔开):" + arr2.join('&') + "<br><br>");

//3.文字数组 排序 - sort()
document.write("排序前:" + arr + "<br><br>");
document.write("排序后:" + arr.sort() + "<br><br>");

//4.数字排序 - sort()
document.write(arrInt.sort() + "<br><br>");
document.write(arrInt2.sort() + "<br><br>");
</script>

你可能感兴趣的:(js)