美文网首页
JS -- 数组

JS -- 数组

作者: MingJiang3 | 来源:发表于2018-08-16 22:24 被阅读0次

    数组:按次序排列的一组值(用array构造出来的对象)

    伪数组:形式长得像数组但原型链中没有Array.prototype这环(arguments也是伪数组)

    1、var a = Array( 3 ):创建一个长度为3的数组(对象),里面只有length = 3(_ _proto_ _)

    2、var a = Array( 3 , 3 ):创建一个数组(对象),里面参数有0 : 3 , 1 : 3 , length = 2 (_ _proto_ _;1和2表示js的不一致性)

    3、sort( )排序:默认从小到大排序,括号里可传函数。x-y时,从小到大排;y-x时,从大到小排。

    sort( )排序1 sort( )排序2

    4、forEach:

    5、join( )插入

    join( ) API

    6、concat( )联接

    concat( )联接 concat( )复制

    7、map( )映射

    (map会形成一个新数组,forEach不会)

    8、filter( )过滤

    9、reduce( )减少为单个值

    reduce和其他API关系


    (for i 循环和  Array.prototype.forEach 都可以遍历数组,区别为:①for 循环可以 break 和 continue;Array.prototype.forEach 不支持 break 和 continue。②for 是关键字,不是函数;Array.prototype.forEach 是一个函数)


    相关文章

      网友评论

          本文标题:JS -- 数组

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