javascript当中concat,join,slice用法

例 1.3(concat,join,slice)
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <Script>
        /* 马克-to-win:qixy: Array is a dynamic array.
         - myArray = new Array(aLength)
        - myArray = new Array(anItem1, anItem2, anItem3, ...)
        */
        var arr = new Array(1);//arr.length is 1,但是里面的东西是undefined, 所以这样写[undefined]
/*虽然arr是个object, 但是里面的东西是undefined*/
        document.write("typeof arr is "+typeof(arr));
        var a = new Array(2, 6, 5, "a");
         document.write("arr.length is "+arr.length+"a.length is "+a.length);
        var b = new Array(12, 14);
        arr[0] = "java";
        arr[1] = "intel";
        arr[2] = "microsoft";
        /* Property/method value type: Array object
       JavaScript syntax: - myArray.concat(someValues, ...)
       The result of this method is a new array consisting of the original array, plus the concatenation.
       The values that are passed to the method are added to the end of the array.
       If arrays are passed, they are flattened and their individual elements added.
       The method returns an array consisting of the original Array plus the concatenated values.
       If Array1 contains "AAA", "BBB", "CCC" and Array2 contains "000", "111", "222", then the method
   call Array1.concat(Array2) will return an array with all the elements in a single collection. The
    original arrays will be untouched.
        */
        document.write("arr.toString() is " + arr.toString() + "<br>");
        //与无参join()方法等同
        var arrconcat=arr.concat(a, b);
        document.write("arr.concat(a,b) is " + arrconcat + "<br>");
        /*Array.join() (Method)
        Concatenate array elements to make a string.
        Property/method value type: String primitive
        JavaScript syntax: - myArray.join(aSeparator)
        Argument list: aSeparator A string to place between array elements as the array is concatenated to form a string.
        //无参join()方法默认是用逗号连接
        */
        document.write("arr.join() is " + arr.join() + "<br>");
        //无参join()方法默认是用逗号连接
        document.write("arr.join(' & ') is " + arr.join(' & ') + "<br>");
        /* Array.reverse() (Method)
        Reverse the order of array elements.
        Property/method value type: Array object
        */
        document.write("arr.reverse() is " + arr.reverse() + "<br>");
        /*Array.sort() (Method)
        Sort the elements in an array.
        Property/method value type: Array object
        JavaScript syntax: - myArray.sort()
        */   

更多请见:https://blog.csdn.net/qq_43650923/article/details/100120352

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mark_to_win

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值