美文网首页
数组的API

数组的API

作者: yangmengjiao | 来源:发表于2018-09-18 19:14 被阅读0次
join(' ') 拼接
split(' ')把字符串分割为字符串数组
reverse()颠倒数组中元素顺序
<div id="itany">
    <p>{{count}}</p>
</div>
<script>
    new Vue({
        el:'#itany',
        data:{
            mes:'hello vue'
        },
        computed:{
            count:function(){
                return this.mes.split(' ').reverse().join('---')
            }
        }
    })
//输出结果为:vue---hello
</script>

concat()链接两个字符串
var str1="Hello "
var str2="world!"
document.write(str1.concat(str2))
//输出结果为:Hello world!

String() 函数把对象的值转换为字符串。
<script type="text/javascript">

var test1= new Boolean(1);
document.write(String(test1));
</script>

slice()提取字符串的某个部分,并以新的字符串返回被提取的部分
var str="Hello happy world!"
document.write(str.slice(6))//输出结果为:happy world
document.write(str.slice(6,11))//输出结果为:happy

push()向数组末尾添加一个或多个元素
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.push("James") )//输出结果为:4
document.write(arr)//输出结果为:George,John,Thomas,James

unshift()向数组的开头添加一个或更多元素,并返回新的长度
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.unshift('Tom'))//输出结果为:4
document.write(arr)//输出结果为:Tom,George,John
shift()删除并返回数组的第一个元素
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.shift())//输出结果为:George
document.write(arr)//输出结果为:John,Thomas


pop()删除并返回最后一个元素
var arr = new Array(3)
arr[0] = "George"
arr[1] = "John"
arr[2] = "Thomas"
document.write(arr.pop())//输出结果为:Thomas
document.write(arr)//输出结果为:George,John


相关文章

  • JS数组方法

    1.数组的Api 2.ES5数组的Api 数组方法的 filter 、map、every、some 对比试验 3....

  • ios开发 数组模型排序的集中方法

    数组排序的API分为2中,一种是数组直接调用API排序,另一种根据NSSortDescriptor来排序 //数组...

  • 数组的API

  • 数组的API

  • 数组API

    数据API: 1.string();把数组转换成字符串 代码如下 2.join('拼接符');拼接,最后拼接成的是...

  • 数组API:

    1.String(); 吧数组穿换成字符串 案例: 2.join('拼接符'); 拼接成字符串,如果没有拼接符,默...

  • 数组API

    数组API 1.String();把数组转化为字符串 var a=[1,2,3,4,5]; ...

  • 数组API

    1.String(); 把数组转换成字符串 var arr=[1,2,3,4,5]; var ...

  • 数组api

    1string() 将数组转化为字符串并分隔每个元素; 2 join() 连接 3 concat()拼接不会改变...

  • 数组API

    Javascript数组API: 1、将数组转化为字符串:2种: var str=String(str);将数组转...

网友评论

      本文标题:数组的API

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