当前位置:   article > 正文

split,join,slice,splice_join split

join split
  1. 数组转字符
var a, b;
a = [0,1,2,3,4];
b = a.join("-");      //"0-1-2-3-4"
  • 1
  • 2
  • 3
  1. 字符串转数组
var str = "aaa,bbb,ccc";
strArr = str.split(",");// 在每个逗号(,)处进行分解  ["aaa", "bbb", "ccc"]
var hello = "helloworld";
helloArr = hello.split('');  //["h", "e", "l", "l", "o", "w", "o", "r", "l", "d"]
  • 1
  • 2
  • 3
  • 4
  1. 截取
let day = [1,2,4,5]
day.slice(0, -1)  // [1, 2, 4]   去掉了最后一个
  • 1
  • 2
  1. 删除
let array = [1, 2, 3]
array.splice(index, 1)  //index是下标,1是长度  array.splice(1, 1) 就得到[1,3]!!!!!!!!!!!!!!!对原数组进行了修改
  • 1
  • 2
声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号