Skip to content
Mak Sò edited this page Mar 22, 2015 · 1 revision

Array prototypes

  • first

    First element in an array

    [1,2,3,3,4,5,6,7,8,8,9,6,5,4].first()

    result

    1

  • last

    Last element in an array

    [1,2,3,3,4,5,6,7,8,8,9,6,5,4].last()

    result

    4

  • containElement

    check if an array contain an element

    ["A","B","C","D","E","F"].containElement("A")

    result

    true

  • eliminateDuplicate

    Eliminate all element duplicated in an array

    [1,2,3,3,4,5,6,7,8,8,9,6,5,4].even()

    result

    [1,2,3,4,5,6,7,8,9]

  • remove(element/[elements])

    Remove elements in an array

    • example 1

      [1,2,3,3].remove(3)

      result

      [1,2]

    • example 2

      ["A","B","C","D","E","F"].remove(["A","B","C"])

      result

      ["D","E","F"]

  • generateScale(type,style,start,end,interval)

    generate an array of specific element

    • example 1

      var myarray = Array().generateScale('letters','upper','a','c',null)

      result

      ["A","B","C"]

    • example 2

      var myarray = Array().generateScale('letters','lower','a','f',2)

      result

      ["a","c","e"]

    • example 3

      var myarray = Array().generateScale('numbers',null,0,9,3)

      result

      [0,3,6,9]

    • example 4

      var myarray = Array().generateScale('numbers',null,-9,0,1)

      result

      [-9,-8,-7,-6,-5,-4,-3,-2,-1,0]

  • even

    Take all even numbers in an array

    [1,2,3,3,4,5,6,7,8,8,9,6,5,4].even()

    result

    [2,4,6,8,8,6,4]

  • evenIndex

    Take all even index in an array

    ["a","A","b","B","c","C","d","D","e","E","f","F"].evenIndex()

    result

    ["a","b","c","d","e","f"]

  • odd

    Take all odd numbers in an array

    [1,2,3,3,4,5,6,7,8,8,9,6,5,4].odd()

    result

    [1,3,3,5,7,9,5]

  • oddIndex

    Take all odd index in an array

    ["a","A","b","B","c","C","d","D","e","E","f","F"].oddIndex()

    result

    ["A","B","C","D","E","F"]