JS objects - the array summary (create, properties, methods) JS objects - Array summary (create, properties, methods)

 

 

 1, create a string

  1.1 new Array()

    var arr1 = new Array();

    var arr2 = new Array (6); length of the array 6

    var arr3 = new Array (1, 2, 3, 4); parentheses item in the array elements, length is the number of elements

  1.2 [] (abbreviation)

    was arr4 = [1,2,3,4] 

2, the properties of the array

  2.1 constructor

         References to create an array of objects Array constructor,
  2.2 length 

    Length of the array

  2.3 prototype

    Each has a function we create the prototype (prototype) property, which is a pointer to an object, the object is to use the properties and methods that can be shared by all instances of a particular type comprising. prototype method allows us to have the ability to add properties and methods to an object.

3, an array of methods

   3.1 Common Array method

    concat connect two or more arrays, return results.   

     

    join all of the elements in the array by making into a string delimiter.

    

    pop Removes and returns the last element of the array.

    

     push append one or more elements to the end of the array, and returns the length of the elements of the array increases.

     

    reverse reverse the order of elements in the array. 

     

    shift Removes and returns the first element of the array. 

     

    unshift add one or more elements to the beginning of the array, and returns the new length. 

     

 

  

    slice Returns selected elements from the array.  

      

    sort the elements of the array to sort, and returns sorted array.   

     

    splice remove elements, delete and add an array of new elements position, return the element removed.  

     

    toString  将数组转换成字符串,元素之间用 ‘,’ 隔开。 

     

    valueOf  返回数组对象的原始值。

  3.2

        

  3.3 数组新增方法

    map  通过制定方法处理数组中的每一个元素,并返回处理后的数组。

      

 

    find  检索数组中的元素,并返回第一个符合要求的元素

      

 

    filter   检索数组中的元素,并以数组的形式返回所有符合要求的元素

      

 

    every  检测数组中的每一个元素是否符合条件,是则返回true,否则是false.

     

    some  检测数组中是否符合条件的元素,有则返回true,否则是false.

      

    foreach  循环遍历数组的元素,作用相当于for循环。

      

 

 

 

 1、创建字符串

  1.1 new Array()

    var arr1 = new Array();

    var arr2 = new Array(6);  数组的长度为6

    var arr3 = new Array(1, 2, 3, 4);   括号中的元素为数组的项, length为元素个数

  1.2  []  (简写)

    var arr4 = [1,2,3,4] 

2、数组的属性

  2.1 constructor

         对创建数组对象的Array构造函数的引用,
  2.2 length 

    数组的长度

  2.3 prototype

    我们创建的每一个函数都有一个prototype(原型)属性,这个属性是一个指针,指向一个对象,而这个对象的用途是包含可以由特定类型的所有实例共享的属性和方法。prototype方法能让我们有能力向对象添加属性和方法。

3、数组的方法

   3.1常用数组方法

    concat  连接两个或多个数组,返回结果。   

     

    join    将数组中所有的元素通过制定的分割符放入一个字符串中。

    

    pop    删除并返回数组的最后一个元素。

    

     push    向数组末尾追加一个或多个元素,并返回数组的增加元素后的长度。

     

    reverse   颠倒数组中元素的顺序。 

     

    shift    删除并返回数组的第一个元素。 

     

    unshift   向数组的开头添加一个或多个元素,并返回新的长度。 

     

 

  

    slice    从数组中返回已选定的元素。  

      

    sort    对数组的元素进行排序,并返回排序后的数组。   

     

    splice    删除元素,并向数组中删除的位置添加新的元素,返回删除的元素。  

     

    toString  将数组转换成字符串,元素之间用 ‘,’ 隔开。 

     

    valueOf  返回数组对象的原始值。

  3.2

        

  3.3 数组新增方法

    map  通过制定方法处理数组中的每一个元素,并返回处理后的数组。

      

 

    find  检索数组中的元素,并返回第一个符合要求的元素

      

 

    filter   检索数组中的元素,并以数组的形式返回所有符合要求的元素

      

 

    every  检测数组中的每一个元素是否符合条件,是则返回true,否则是false.

     

    some  检测数组中是否符合条件的元素,有则返回true,否则是false.

      

    foreach  循环遍历数组的元素,作用相当于for循环。

      

 

Guess you like

Origin www.cnblogs.com/itgezhu/p/11263452.html