美文网首页uniApp
uniapp 数组操作

uniapp 数组操作

作者: GloryMan | 来源:发表于2019-11-13 09:20 被阅读0次

    字符串转数组

    let string = "12345,56789"
    string.split(',') // ['12345','56789']

    数组转字符串

    let array = ["123","456"]
    array.join(",") // "'123','456'"

    数组元素删除

    let array = ['123','456']
    // 删除起始下标为1,长度为1的一个值,len设置的1,如果为0,则数组不变
    array.splice(1,1) // ['123']

    // 替换起始下标为1,长度为1的一个值为‘ttt’,len设置的1
    array.splice(1,1,'ttt') // ['123','ttt']

    长度为0 位添加一个元素

    // 表示在下标为1处添加一项‘ttt’
    array.splice(1,0,'ttt') //['123','ttt','456']

    // 数组是否包含某个元素
    arr.indexOf(某元素):未找到则返回 -1。

    相关文章

      网友评论

        本文标题:uniapp 数组操作

        本文链接:https://www.haomeiwen.com/subject/tdkqictx.html