删除字符串方法详细报告

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

 

转载于:https://www.cnblogs.com/lujunan/p/10315101.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值