<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js数组的push pop split concat join</title>
<script src="script/jquery-1.1.3.1.js" type="text/javascript"></script>
<script type="text/javascript">
var arr1 = new Array(3);
var arr2 = new Array(3,2);
var arr1_string = "";
arr1.push("12");
arr2.push("12");
document.write(arr1+"<br/>");
//显示的竟然是,,,12。new Array一个参数表示数组元素个数,且已经赋值为空
document.write(arr2+"<br/>"); //显示的竟然是3,2,12。new Array两个及以上参数表示数组元素的内容,且参数和数组的元素相同
arr2.pop("2");
document.write(""+arr2+"<br/>");//显示12没了,无论pop的参数是什么,都是去掉最后一个,后进先出
arr1 = arr2.concat();
document.write("arr1 = arr2.concat() "+arr1+"<br />");//结果为3,2,直接将数组2中的所有内容覆盖给arr1
arr1_string = arr1.join();
document.write("arr1_string: "+arr1_string);
document.write("数组arr1第二个元素: "+arr1_string.split(",")[1]); // 显示的arr1_string和arr1一样,也是2,3,但是前者是string类型,后者是数组类型。
</script>
</head>
<body>
</body>
</html>
js数组的push pop split concat join
最新推荐文章于 2023-02-01 10:14:32 发布