Blogger Information
Blog 12
fans 0
comment 0
visits 5386
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1. 队列与循环队列; 2. 演示字符串与数组方法(至少3个) 3. 演示class的用法(属性,方法,访问器属性,继承)
汉邦
Original
257 people have browsed it

演示字符串与数组方法

  1. str.search(): 字符->索引

    1. let str = 'php中文网'
    2. console.log(str.search('文'))
  2. str.replace(): 替换, php”中文网”->php”.cn”

    1. console.log(str.replace('中文网', '.cn'))
  3. str.slice(): 子串, 获取’php’(忽略结束索引的字符)

    1. console.log(str.slice(0,3))

    常用数组方法

    尾部: push(),pop()
    增加:

    1. let arr = []
    2. console.log(arr.push('a'))
    3. console.log(arr)

    删除:从尾部删除一个

    1. console.log(arr.pop())

    头部: unshift(), shift()

    1. console.log(arr.unshift('A'))
    2. console.log(arr)
    1. console.log(arr.shift())

    删除任意位置

    1. arr = [1, 2, 3, 4, 5]
    2. console.log(delete arr[2])
    3. console.log(arr)

    获取数组的键:keys

    1. for (let key of arr.keys()) {
    2. console.log(key)
    3. }

    获取数组的值:values

    1. for (let value of arr.values()) {
    2. console.log(value)
    3. }

队列:

  1. arr = ['a','b','c','d']
  2. function que1(arr, str){
  3. arr.push(str)
  4. arr.shift()
  5. }
  6. console.log(arr);
  7. que1(arr, 'e')
  8. console.log(arr);
  9. que1(arr, 'f')
  10. console.log(arr);

循环队列:

  1. arr = ['a','b','c','d']
  2. function que2(arr){
  3. let a = arr.shift()
  4. arr.push(a)
  5. }
  6. console.log(arr);
  7. que2(arr)
  8. console.log(arr);
  9. que2(arr)
  10. console.log(arr);
  11. for(let key of arr.entries()){
  12. console.log(key);
  13. }
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post