<!DOCTYPE?html>?
<html?xmlns="http://www.w3.org/1999/xhtml">
<head>
????<title></title>
????<script?type="text/javascript">
????????//創建數組的同時對元素賦值
????????var?arr?=?new?Array("html",?"css",?"javascript");
????????arr.unshift("jQuery",?"Ajax");
????????document.write("添加新元素后的數組元素:"?+arr);
????</script>
</head>
<body>
</body>
</html>
代碼這樣寫,輸入的結果是“添加新元素后的數組元素:jQuery,Ajax,html,css,javascript”。要是代碼改成下面的:<!DOCTYPE?html>?
<html?xmlns="http://www.w3.org/1999/xhtml">
<head>
????<title></title>
????<script?type="text/javascript">
????????//創建數組的同時對元素賦值
????????var?arr?=?new?Array("html",?"css",?"javascript");
????????document.write("添加新元素后的數組元素:"+arr.unshift("jQuery",?"Ajax"));
????</script>
</head>
<body>
</body>
</html>
輸出結果就成了“添加新元素后的數組元素:5”。就成了數組的長度了。上面的“arr.unshift("jQuery",?"Ajax");”是怎么回事?什么情況下可以這樣用?先拜謝各位老師了!
unshift問題求教
天窗的螞蟻
2016-01-23 22:31:29