实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<body>
4
5
<p id="demo">Click the button to add elements to the array.</p>
6
7
<button onclick="myFunction()">Try it</button>
8
9
<script>
10
function myFunction()
11
{
12
var fruits = ["Banana", "Orange", "Apple", "Mango"];
13
fruits.unshift("Lemon","Pineapple");
14
var x=document.getElementById("demo");
15
x.innerHTML=fruits;
16
}
17
</script>
18
19
<p><b>Note:</b> The unshift() method does not work properly in Internet Explorer 8 and earlier, the values will be inserted, but the return value will be <em>undefined</em>.</p>
20
21
</body>
22
</html>