• Array
  • Date
  • Function
  • Number
  • Object
  • Range
  • RegExp
  • String
  • Sugar
Type Name Module
All Default Bookmarked
  • construct ( n , indexMapFn )

    Constructs an array of n length from the values of indexMapFn. This function is essentially a shortcut for using Array.from with new Array(n).

    • Callback: indexMapFn

      i The index of the current iteration.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Array.construct(4, function(i) {
      return i * i;
    });

    Source

  • create ( [ obj ] , [ clone ]  = false )

    Creates an array from an unknown object. This method is similar to native Array.from but is faster when obj is already an array. When clone is true, the array will be shallow cloned. Additionally, it will not fail on undefined, null, or numbers, producing an empty array in the case of undefined and wrapping obj otherwise.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Array.create()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Array.create(8)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Array.create('abc')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Array.create([1,2,3])

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Array.create(undefined)

    Source

  • from ( a , [ mapFn ] , [ context ] )

    Creates an array from an array-like object. If mapFn is passed, it will be map each element of the array. context is the this object if passed. This method is provided as a polyfill.

    • Callback: mapFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Array.from({0:'a',1:'b',length:2});

    Source

  • isArray ( obj )

    Returns true if obj is an Array. This method is provided as a polyfill.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Array.isArray(3)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Array.isArray(true)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Array.isArray('wasabi')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Array.isArray([1,2,3])

    Source

  • add ( item , [ index ] )

    Adds item to the array and returns the result as a new array. If item is also an array, it will be concatenated instead of inserted. index will control where item is added. Use append to modify the original array.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4].add(5)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4].add(8, 1)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4].add([5,6,7])

    Source

  • append ( item , [ index ] )

    Appends item to the array. If item is also an array, it will be concatenated instead of inserted. This method modifies the array! Use add to create a new array. Additionally, insert is provided as an alias that reads better when using an index.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4].append(5)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4].append([5,6,7])

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4].append(8, 1)

    Source

  • at ( index , [ loop ]  = false )

    Gets the element(s) at index. When loop is true, overshooting the end of the array will begin counting from the other end. index can be negative. If index is an array, multiple elements will be returned.

    Returns: ArrayElement

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].at(0)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].at(2)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].at(4)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].at(4, true)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].at(-1)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].at([0, 1])

    Source

  • average ( [ map ] )

    Gets the mean average for all values in the array. map can be a function of type mapFn that maps the value to be averaged or a string acting as a shortcut. Supports deep properties.

    • Callback: mapFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Number

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4].average()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.average(function(user) {
      return user.age;
    });

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.average('age')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.average('currencies.usd.balance')

    Source

  • clone ( )

    Creates a shallow clone of the array.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].clone()

    Source

  • compact ( [ all ]  = false )

    Removes all instances of undefined, null, and NaN from the array. If all is true, all "falsy" elements will be removed. This includes empty strings, 0, and false.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,null,2,undefined,3].compact()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,'',2,false,3].compact()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,'',2,false,3].compact(true)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [null, [null, 'bye']].compact()

    Source

  • count ( search , [ context ] )

    Counts all elements in the array that match search. search can be an element or a function of type searchFn. Implements enhanced matching.

    • Callback: searchFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Number

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','a'].count('a')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].count(/b/)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.count(function(user) {
      return user.age > 30;
    });

    Source

  • every ( search , [ context ] )

    Returns true if search is true for all elements of the array. search can be an array element or a function of type searchFn. context is the this object. Implements enhanced matching. This method is also provided as a polyfill in the ES5 module.

    • Callback: searchFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','a','a'].every(function(n) {
      return n == 'a';
    });

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','a','a'].every('a')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [{a:2},{a:2}].every({a:2})

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.every({ name: /^H/ })

    Source

  • exclude ( search )

    Returns a new array with every element that does not match search. search can be an array element or a function of type searchFn. This method can be thought of as the inverse of Array#filter. It will not modify the original array, Use remove to modify the array in place. Implements enhanced matching.

    • Callback: searchFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].exclude(3)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].exclude(/b/)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [{a:1},{b:2}].exclude(function(n) {
      return n['a'] == 1;
    });

    Source

  • filter ( search , [ context ] )

    Returns any elements in the array that match search. search can be an array element or a function of type searchFn. context is the this object. Implements enhanced matching. This method is also provided as a polyfill in the ES5 module.

    • Callback: searchFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].filter(function(n) {
      return n > 1;
    });

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,2,4].filter(2)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.filter({ name: /^H/ })

    Source

  • find ( search , [ context ] )

    Returns the first element in the array that matches search. search can be an array element or a function of type searchFn. Implements enhanced matching. This method is also provided as a polyfill in the ES6 module.

    • Callback: searchFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.find(function(user) {
      return user.name === 'Harry';
    });

    Source

  • findIndex ( search , [ context ] )

    Returns the index of the first element in the array that matches search, or -1 if none. search can be an array element or a function of type searchFn. context is the this object. Implements enhanced matching. This method is also provided as a polyfill in the ES6 module.

    • Callback: searchFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Number

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4].findIndex(function(n) {
      return n % 2 == 0;
    });

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].findIndex('c');

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['cuba','japan','canada'].find(/^c/)

    Source

  • first ( [ num ]  = 1 )

    Returns the first element(s) in the array. When num is passed, returns the first num elements in the array.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].first()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].first(2)

    Source

  • flatten ( [ limit ]  = Infinity )

    Returns a flattened, one-dimensional copy of the array. You can optionally specify a limit, which will only flatten to that depth.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [[1], 2, [3]].flatten()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [[1],[],2,3].flatten()

    Source

  • fnFromIndex ( startIndex , [ loop ] , [ ... )

    Runs native array functions beginning from startIndex. If loop is true, once the end of the array has been reached, iteration will continue from the start of the array up to startIndex - 1. If loop is false it can be omitted. Standard arguments are then passed which will be forwarded to the native methods. When available, methods are always enhanced. This includes deep properties for map, and enhanced matching for some, every, filter, find, and findIndex. Note also that forEachFromIndex is optimized for sparse arrays and may be faster than native forEach.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.mapFromIndex(2, 'name');

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.mapFromIndex(2, true, 'name');

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    names.forEachFromIndex(10, log);

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    names.everyFromIndex(15, /^[A-F]/);

    Methods

    • mapFromIndex
    • forEachFromIndex
    • filterFromIndex
    • someFromIndex
    • everyFromIndex
    • reduceFromIndex
    • reduceRightFromIndex
    • findFromIndex
    • findIndexFromIndex

    Source

  • forEach ( [ eachFn ] , [ context ] )

    Iterates over the array, calling eachFn on each loop. context becomes the this object. This method is provided as a polyfill.

    • Callback: eachFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.
    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].forEach(function(a) {
      // Called 3 times: 'a','b','c'
    });

    Source

  • from ( index )

    Returns a slice of the array from index.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].from(1)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].from(2)

    Source

  • groupBy ( map , [ groupFn ] )

    Groups the array by map. Will return an object whose keys are the mapped from map, which can be a callback of type mapFn, or a string acting as a shortcut. map supports deep properties. Optionally calls groupFn for each group.

    • Callback: mapFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.
    • Callback: groupFn

      arr The current group as an array.
      key The unique key of the current group.
      obj A reference to the object.

    Returns: Object

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','aa','aaa'].groupBy('length')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.groupBy(function(n) {
      return n.age;
    });

    Source

  • inGroups ( num , [ padding ] )

    Groups the array into num arrays. If specified, padding will be added to the last array to be of equal length.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4,5,6,7].inGroups(3)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4,5,6,7].inGroups(3, 0)

    Source

  • inGroupsOf ( num , [ padding ]  = null )

    Groups the array into arrays of num elements each. padding will be added to the last array to be of equal length.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4,5,6,7].inGroupsOf(4)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4,5,6,7].inGroupsOf(4, 0)

    Source

  • includes ( search , [ fromIndex ]  = 0 )

    Returns true if search is contained within the array. Search begins at fromIndex, which defaults to the beginning of the array. This method is provided as a polyfill.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].includes(2)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].includes(4)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].includes(2, 3)

    Source

  • indexOf ( search , [ fromIndex ]  = 0 )

    Searches the array and returns the first index where search occurs, or -1 if the element is not found. fromIndex is the index from which to begin the search. This method performs a simple strict equality comparison on search. Sugar does not enhance this method to support enhanced matching. For such functionality, use the findIndex method instead. This method is provided as a polyfill.

    Returns: Number

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].indexOf(3)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].indexOf(7)

    Source

  • insert ( item , [ index ] )

    Appends item to the array at index. This method is simply a more readable alias for append when passing an index. If el is an array it will be joined. This method modifies the array! Use add as a non-destructive alias.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,3,4,5].insert(2, 1)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,4,5,6].insert([2,3], 1)

    Source

  • intersect ( arr )

    Returns a new array containing any elements that both arrays have in common. In addition to primitives, this method will also deep-check objects for equality.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,3,5].intersect([5,7,9])

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b'].intersect(['b','c'])

    Source

  • isEmpty ( )

    Returns true if the array has a length of zero.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [].isEmpty()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a'].isEmpty()

    Source

  • isEqual ( arr )

    Returns true if the array is equal to arr. Objects in the array are considered equal if they are not observably distinguishable. This method is an instance alias for Object.isEqual().

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b'].isEqual(['a','b'])

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b'].isEqual(['a','c'])

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [{a:'a'}].isEqual([{a:'a'}])

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [5].isEqual([Object(5)])

    Source

  • last ( [ num ]  = 1 )

    Returns the last element(s) in the array. When num is passed, returns the last num elements in the array.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].last()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].last(2)

    Source

  • lastIndexOf ( search , [ fromIndex ]  = array.length - 1 )

    Searches the array from the end and returns the first index where search occurs, or -1 if the element is not found. fromIndex is the index from which to begin the search. This method performs a simple strict equality comparison on search. Sugar does not enhance this method to support enhanced matching. This method is provided as a polyfill.

    Returns: Number

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,1].lastIndexOf(1)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,1].lastIndexOf(7)

    Source

  • least ( [ all ]  = false , [ map ] )

    Returns the elements in the array with the least commonly occuring value. map can be passed in place of all, and is a function of type mapFn that maps the value to be checked or a string acting as a shortcut. If all is true, will return multiple values in an array. Supports deep properties.

    • Callback: mapFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [3,2,2].least()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['fe','fo','fum'].least(true, 'length')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.least('profile.type')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.least(true, 'profile.type')

    Source

  • map ( map , [ context ] )

    Maps the array to another array whose elements are the values returned by map. context is the this object. Sugar enhances this method to accept a string for map, which is a shortcut for a function that gets a property or invokes a function on each element. Supports deep properties. This method is also provided as a polyfill in the ES5 module.

    • Callback: mapFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: New Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].map(function(n) {
      return n * 3;
    });

    Source

  • max ( [ all ]  = false , [ map ] )

    Returns the element in the array with the greatest value. map can be passed in place of all, and is a function of type mapFn that maps the value to be checked or a string acting as a shortcut. If all is true, multiple elements will be returned. Supports deep properties.

    • Callback: mapFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].max()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['fee','fo','fum'].max('length')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['fee','fo','fum'].max(true, 'length')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.max('age')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['fee','fo','fum'].max(true, function(n) {
      return n.length;
    });

    Source

  • median ( [ map ] )

    Gets the median average for all values in the array. map can be a function of type mapFn that maps the value to be averaged or a string acting as a shortcut.

    • Callback: mapFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Number

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,2].median()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [{a:1},{a:2},{a:2}].median('a')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.median('age')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.median('currencies.usd.balance')

    Source

  • min ( [ all ]  = false , [ map ] )

    Returns the element in the array with the lowest value. map can be passed in place of all, and is a function of type mapFn that maps the value to be checked or a string acting as a shortcut. If all is true, multiple elements will be returned. Supports deep properties.

    • Callback: mapFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].min()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['fee','fo','fum'].min('length')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['fee','fo','fum'].min(true, 'length')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.min('age')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['fee','fo','fum'].min(true, function(n) {
      return n.length;
    });

    Source

  • most ( [ all ]  = false , [ map ] )

    Returns the elements in the array with the most commonly occuring value. map can be passed in place of all, and is a function of type mapFn that maps the value to be checked or a string acting as a shortcut. If all is true, will return multiple values in an array. Supports deep properties.

    • Callback: mapFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [3,2,2].most(2)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['fe','fo','fum'].most(true, 'length')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.most('profile.type')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.most(true, 'profile.type')

    Source

  • none ( search , [ context ] )

    Returns true if none of the elements in the array match search. search can be an array element or a function of type searchFn. context is the this object. Implements enhanced matching.

    • Callback: searchFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].none(5)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].none(/b/)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.none(function(user) {
      return user.name == 'Wolverine';
    });

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.none({ name: 'Wolverine' });

    Source

  • reduce ( reduceFn , [ init ] )

    Reduces the array to a single result. This operation is sometimes called "accumulation", as it takes the result of the last iteration of reduceFn and passes it as the first argument to the next iteration, "accumulating" that value as it goes. The return value of this method will be the return value of the final iteration of reduceFn. If init is passed, it will be the initial "accumulator" (the first argument). If init is not passed, then it will take the first element in the array, and reduceFn will not be called for that element. This method is provided as a polyfill.

    • Callback: reduceFn

      acc The "accumulator". Either init, the result of the last iteration of reduceFn, or the first element of the array.
      el The current element for this iteration.
      idx The current index for this iteration.
      arr A reference to the array.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].reduce(function(a, b) {
      return a - b; // 1 - 2 - 3
    });

    Source

  • reduceRight ( [ reduceFn ] , [ init ] )

    Similar to Array#reduce, but operates on the elements in reverse. This method is provided as a polyfill.

    • Callback: reduceFn

      acc The "accumulator", either init, the result of the last iteration of reduceFn, or the last element of the array.
      el The current element for this iteration.
      idx The current index for this iteration.
      arr A reference to the array.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].reduceRight(function(a, b) {
      return a - b; // 3 - 2 - 1
    });

    Source

  • remove ( search )

    Removes any element in the array that matches search. search can be an array element or a function of type searchFn. This method will modify the array! Use exclude for a non-destructive alias. This method implements enhanced matching.

    • Callback: searchFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].remove(3)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].remove(/b/)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [{a:1},{b:2}].remove(function(n) {
      return n['a'] == 1;
    });

    Source

  • removeAt ( start , [ end ] )

    Removes element at start. If end is specified, removes the range between start and end. This method will modify the array!

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].removeAt(0)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4].removeAt(1, 2)

    Source

  • sample ( [ num ]  = 1 , [ remove ]  = false )

    Returns a random element from the array. If num is passed, will return an array of num elements. If remove is true, sampled elements will also be removed from the array. remove can also be passed in place of num.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4,5].sample()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4,5].sample(1)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4,5].sample(3)

    Source

  • shuffle ( )

    Returns a copy of the array with the elements randomized. Uses Fisher-Yates algorithm.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3,4].shuffle()

    Source

  • some ( search , [ context ] )

    Returns true if search is true for any element in the array. search can be an array element or a function of type searchFn. context is the this object. Implements enhanced matching. This method is also provided as a polyfill in the ES5 module.

    • Callback: searchFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Boolean

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].some(function(n) {
      return n == 'a';
    });

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].some(function(n) {
      return n == 'd';
    });

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].some('a')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [{a:2},{b:5}].some({a:2})

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.some({ name: /^H/ })

    Source

  • sortBy ( [ map ] , [ desc ]  = false )

    Enhanced sorting function that will sort the array by map. map can be a function of type sortMapFn, a string acting as a shortcut, an array (comparison by multiple values), or blank (direct comparison of array values). map supports deep properties. desc will sort the array in descending order. When the field being sorted on is a string, the resulting order will be determined by an internal collation algorithm that is optimized for major Western languages, but can be customized using sorting accessors such as sortIgnore. This method will modify the array!

    • Callback: sortMapFn

      el An array element.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['world','a','new'].sortBy('length')

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['world','a','new'].sortBy('length', true)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.sortBy(function(n) {
      return n.age;
    });

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.sortBy('age')

    Source

  • subtract ( item )

    Subtracts item from the array and returns the result as a new array. If item is also an array, all elements in it will be removed. In addition to primitives, this method will also deep-check objects for equality.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,3,5].subtract([5,7,9])

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b'].subtract(['b','c'])

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].subtract(2)

    Source

  • sum ( [ map ] )

    Sums all values in the array. map can be a function of type mapFn that maps the value to be summed or a string acting as a shortcut.

    • Callback: mapFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Number

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,2].sum()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.sum(function(user) {
      return user.votes;
    });

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.sum('votes')

    Source

  • to ( index )

    Returns a slice of the array up to index.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].to(1)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b','c'].to(2)

    Source

  • union ( arr )

    Returns a new array containing elements in both arrays with duplicates removed. In addition to primitives, this method will also deep-check objects for equality.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,3,5].union([5,7,9])

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    ['a','b'].union(['b','c'])

    Source

  • unique ( [ map ] )

    Removes all duplicate elements in the array. map can be a string or callback type mapFn that returns the value to be uniqued or a string acting as a shortcut. This is most commonly used when you only need to check a single field that can ensure the object's uniqueness (such as an id field). If map is not passed, then objects will be deep checked for equality. Supports deep properties.

    • Callback: mapFn

      el The element of the current iteration.
      i The index of the current iteration.
      arr A reference to the array.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,2,3].unique()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [{a:'a'},{a:'a'}].unique()

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    users.unique(function(user) {
      return user.id;
    });

    Source

  • zip ( [ arr1 ] , [ arr2 ] , [ ... )

    Merges multiple arrays together. This method "zips up" smaller arrays into one large whose elements are "all elements at index 0", "all elements at index 1", etc. Useful when you have associated data that is split over separated arrays. If the arrays passed have more elements than the original array, they will be discarded. If they have fewer elements, the missing elements will filled with null.

    Returns: Array

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    [1,2,3].zip([4,5,6])

    Source

  • getOption ( name )

    Gets an option used internally by Array. Options listed below. Current options are for sorting strings with sortBy.

    Returns: Mixed

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Sugar.Array.getOption('sortNatural')

    Source

  • setOption ( name , value )

    Sets an option used internally by Array. Options listed below. Current options are for sorting strings with sortBy. If value is null, the default value will be restored.

    Options

    sortIgnore A regex to ignore when sorting. An example usage of this option would be to ignore numbers in a list to instead sort by the first text that appears. Default is null.
    sortIgnoreCase A boolean that ignores case when sorting. Default is true.
    sortNatural A boolean that turns on natural sorting. "Natural" means that numerals like "10" will be sorted after "9" instead of after "1". Default is true.
    sortOrder A string of characters to use as the base sort order. The default is an order natural to most major world languages.
    sortEquivalents A table of equivalent characters used when sorting. The default produces a natural sort order for most world languages, however can be modified for others. For example, setting "ä" and "ö" to null in the table would produce a Scandanavian sort order. Note that setting this option to null will restore the default table, but any mutations made to that table will persist.
    sortCollate The collation function used when sorting strings. The default function produces a natural sort order that can be customized with the other "sort" options. Overriding the function directly here will also override these options.
    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Sugar.Array.setOption('sortIgnore', /^\d+\./)

    Esc ⌃ Enter Extended Default Edit Mode Reset Run
    Sugar.Array.setOption('sortIgnoreCase', false)

    Source

  • No saved methods