36 lines
901 B
HTML
36 lines
901 B
HTML
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>Document</title>
|
||
|
<script>
|
||
|
var arr=[1,2,3] //字面量
|
||
|
// console.log(arr[1])
|
||
|
// for(let i in arr){
|
||
|
// console.log(arr[i]) // i指代的是数组的下标
|
||
|
// }
|
||
|
arr.push(4)
|
||
|
// var q=arr.pop() //pop 返回的是被删除的那个元素
|
||
|
// console.log(arr)
|
||
|
// console.log(q)
|
||
|
arr.shift() //删除第一个元素
|
||
|
arr.unshift(6) //往数组首位添加元素
|
||
|
console.log(arr)
|
||
|
|
||
|
var str=arr.join(',')
|
||
|
console.log(str)
|
||
|
|
||
|
console.log(str.split(','))
|
||
|
|
||
|
// arr.splice(2,1)
|
||
|
arr.splice(2,2,9,0)
|
||
|
console.log(arr)
|
||
|
// splice() 3 2删除 3修改
|
||
|
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
</body>
|
||
|
</html>
|