Correcting teacher:PHPz
Correction status:qualified
Teacher's comments:
str.search(): 字符->索引
let str = 'php中文网'
console.log(str.search('文'))
str.replace(): 替换, php”中文网”->php”.cn”
console.log(str.replace('中文网', '.cn'))
str.slice(): 子串, 获取’php’(忽略结束索引的字符)
console.log(str.slice(0,3))
尾部: push(),pop()
增加:
let arr = []
console.log(arr.push('a'))
console.log(arr)
删除:从尾部删除一个
console.log(arr.pop())
头部: unshift(), shift()
console.log(arr.unshift('A'))
console.log(arr)
console.log(arr.shift())
删除任意位置
arr = [1, 2, 3, 4, 5]
console.log(delete arr[2])
console.log(arr)
获取数组的键:keys
for (let key of arr.keys()) {
console.log(key)
}
获取数组的值:values
for (let value of arr.values()) {
console.log(value)
}
队列:
arr = ['a','b','c','d']
function que1(arr, str){
arr.push(str)
arr.shift()
}
console.log(arr);
que1(arr, 'e')
console.log(arr);
que1(arr, 'f')
console.log(arr);
循环队列:
arr = ['a','b','c','d']
function que2(arr){
let a = arr.shift()
arr.push(a)
}
console.log(arr);
que2(arr)
console.log(arr);
que2(arr)
console.log(arr);
for(let key of arr.entries()){
console.log(key);
}