zoukankan      html  css  js  c++  java
  • 删除字符串方法详细报告

    splice()
    原型:array
    .splice(start[, deleteCount[, item1[, item2[, ...]]]])
    下标,删除数量,增加的字符
     1 ExamplesSection
     2 Remove 0 (zero) elements from index 2, and insert "drum"Section
     3 var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
     4 var removed = myFish.splice(2, 0, 'drum');
     5 
     6 // myFish is ["angel", "clown", "drum", "mandarin", "sturgeon"] 
     7 // removed is [], no elements removed
     8 Remove 1 element from index 3Section
     9 var myFish = ['angel', 'clown', 'drum', 'mandarin', 'sturgeon'];
    10 var removed = myFish.splice(3, 1);
    11 
    12 // removed is ["mandarin"]
    13 // myFish is ["angel", "clown", "drum", "sturgeon"]
    14 Remove 1 element from index 2, and insert "trumpet"Section
    15 var myFish = ['angel', 'clown', 'drum', 'sturgeon'];
    16 var removed = myFish.splice(2, 1, 'trumpet');
    17 
    18 // myFish is ["angel", "clown", "trumpet", "sturgeon"]
    19 // removed is ["drum"]
    20 Remove 2 elements from index 0, and insert "parrot", "anemone" and "blue"Section
    21 var myFish = ['angel', 'clown', 'trumpet', 'sturgeon'];
    22 var removed = myFish.splice(0, 2, 'parrot', 'anemone', 'blue');
    23 
    24 // myFish is ["parrot", "anemone", "blue", "trumpet", "sturgeon"] 
    25 // removed is ["angel", "clown"]
    26 Remove 2 elements from index 2Section
    27 var myFish = ['parrot', 'anemone', 'blue', 'trumpet', 'sturgeon'];
    28 var removed = myFish.splice(myFish.length - 3, 2);
    29 
    30 // myFish is ["parrot", "anemone", "sturgeon"] 
    31 // removed is ["blue", "trumpet"]
    32 Remove 1 element from index -2Section
    33 var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
    34 var removed = myFish.splice(-2, 1);
    35 
    36 // myFish is ["angel", "clown", "sturgeon"] 
    37 // removed is ["mandarin"]
    38 Remove all elements after index 2 (incl.)Section
    39 var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
    40 var removed = myFish.splice(2);
    41 
    42 // myFish is ["angel", "clown"] 
    43 // removed is ["mandarin", "sturgeon"]
    44 Specifications
  • 相关阅读:
    lightoj 1341 Aladdin and the Flying Carpet(算术基本定理)题解
    Bi-shoe and Phi-shoe(欧拉函数/素筛)题解
    HDU 2157(矩阵快速幂)题解
    SPOJ LAS(BFS)题解
    codevs 1106 篝火晚会
    codevs 1137 计算系数
    codevs 1171 潜伏者
    codevs 3732 解方程
    codevs 3290 华容道
    codevs 3289 花匠
  • 原文地址:https://www.cnblogs.com/lujunan/p/10315101.html
Copyright © 2011-2022 走看看