jQuery
Please find a built-in documentation here
Times and Dates
The Control Freak SDK provides a general purpose API dealing with times and dates. This API is implemented by Momentjs
Strings and Numbers
The Control Freak SDK provides a general purpose API dealing with arrays, numbers and strings. This API is implemented by lodash Lodash
Array
-
_.chunk
-
_.compact
-
_.difference
-
_.drop
-
_.dropRight
-
_.dropRightWhile
-
_.dropWhile
-
_.fill
-
_.findIndex
-
_.findLastIndex
-
_.first
-
_.flatten
-
_.flattenDeep
-
_.head
->first
-
_.indexOf
-
_.initial
-
_.intersection
-
_.last
-
_.lastIndexOf
-
_.object
->zipObject
-
_.pull
-
_.pullAt
-
_.remove
-
_.rest
-
_.slice
-
_.sortedIndex
-
_.sortedLastIndex
-
_.tail
->rest
-
_.take
-
_.takeRight
-
_.takeRightWhile
-
_.takeWhile
-
_.union
-
_.uniq
-
_.unique
->uniq
-
_.unzip
-
_.without
-
_.xor
-
_.zip
-
_.zipObject
Chain
-
_
-
_.chain
-
_.tap
-
_.thru
-
_.prototype.chain
-
_.prototype.commit
-
_.prototype.plant
-
_.prototype.reverse
-
_.prototype.run
->value
-
_.prototype.toJSON
->value
-
_.prototype.toString
-
_.prototype.value
-
_.prototype.valueOf
->value
Collection
-
_.all
->every
-
_.any
->some
-
_.at
-
_.collect
->map
-
_.contains
->includes
-
_.countBy
-
_.detect
->find
-
_.each
->forEach
-
_.eachRight
->forEachRight
-
_.every
-
_.filter
-
_.find
-
_.findLast
-
_.findWhere
-
_.foldl
->reduce
-
_.foldr
->reduceRight
-
_.forEach
-
_.forEachRight
-
_.groupBy
-
_.include
->includes
-
_.includes
-
_.indexBy
-
_.inject
->reduce
-
_.invoke
-
_.map
-
_.partition
-
_.pluck
-
_.reduce
-
_.reduceRight
-
_.reject
-
_.sample
-
_.select
->filter
-
_.shuffle
-
_.size
-
_.some
-
_.sortBy
-
_.sortByAll
-
_.sortByOrder
-
_.where
Date
Function
-
_.after
-
_.ary
-
_.backflow
->flowRight
-
_.before
-
_.bind
-
_.bindAll
-
_.bindKey
-
_.compose
->flowRight
-
_.curry
-
_.curryRight
-
_.debounce
-
_.defer
-
_.delay
-
_.flow
-
_.flowRight
-
_.memoize
-
_.negate
-
_.once
-
_.partial
-
_.partialRight
-
_.rearg
-
_.restParam
-
_.spread
-
_.throttle
-
_.wrap
Lang
-
_.clone
-
_.cloneDeep
-
_.isArguments
-
_.isArray
-
_.isBoolean
-
_.isDate
-
_.isElement
-
_.isEmpty
-
_.isEqual
-
_.isError
-
_.isFinite
-
_.isFunction
-
_.isMatch
-
_.isNaN
-
_.isNative
-
_.isNull
-
_.isNumber
-
_.isObject
-
_.isPlainObject
-
_.isRegExp
-
_.isString
-
_.isTypedArray
-
_.isUndefined
-
_.toArray
-
_.toPlainObject
Math
Number
Object
-
_.assign
-
_.create
-
_.defaults
-
_.extend
->assign
-
_.findKey
-
_.findLastKey
-
_.forIn
-
_.forInRight
-
_.forOwn
-
_.forOwnRight
-
_.functions
-
_.has
-
_.invert
-
_.keys
-
_.keysIn
-
_.mapValues
-
_.merge
-
_.methods
->functions
-
_.omit
-
_.pairs
-
_.pick
-
_.result
-
_.transform
-
_.values
-
_.valuesIn
String
-
_.camelCase
-
_.capitalize
-
_.deburr
-
_.endsWith
-
_.escape
-
_.escapeRegExp
-
_.kebabCase
-
_.pad
-
_.padLeft
-
_.padRight
-
_.parseInt
-
_.repeat
-
_.snakeCase
-
_.startCase
-
_.startsWith
-
_.template
-
_.trim
-
_.trimLeft
-
_.trimRight
-
_.trunc
-
_.unescape
-
_.words
Utility
-
_.attempt
-
_.callback
-
_.constant
-
_.identity
-
_.iteratee
->callback
-
_.matches
-
_.matchesProperty
-
_.mixin
-
_.noConflict
-
_.noop
-
_.property
-
_.propertyOf
-
_.range
-
_.runInContext
-
_.times
-
_.uniqueId
Methods
Properties
-
_.VERSION
-
_.support
-
_.support.argsTag
-
_.support.enumErrorProps
-
_.support.enumPrototypes
-
_.support.funcDecomp
-
_.support.funcNames
-
_.support.nodeTag
-
_.support.nonEnumShadows
-
_.support.nonEnumStrings
-
_.support.ownLast
-
_.support.spliceObjects
-
_.support.unindexedChars
-
_.templateSettings
-
_.templateSettings.escape
-
_.templateSettings.evaluate
-
_.templateSettings.imports
-
_.templateSettings.interpolate
-
_.templateSettings.variable
“Array” Methods
_.chunk(array, [size=1])
Creates an array of elements split into groups the length of size
.
If collection
can't be split evenly, the final chunk will be the remaining
elements.
Arguments
-
array
(Array): The array to process. -
[size=1]
(number): The length of each chunk.
Returns
(Array): Returns the new array containing chunks.
Example
_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]
_.chunk(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]
_.compact(array)
Creates an array with all falsey values removed. The values false
, null
,
0
, ""
, undefined
, and NaN
are falsey.
Arguments
-
array
(Array): The array to compact.
Returns
(Array): Returns the new array of filtered values.
Example
_.compact([0, 1, false, 2, '', 3]);
// => [1, 2, 3]
_.difference(array, [values])
Creates an array excluding all values of the provided arrays using
SameValueZero
for equality comparisons.
Note: SameValueZero
comparisons are like strict equality comparisons,
e.g. ===
, except that NaN
matches NaN
. See the
ES spec
for more details.
Arguments
-
array
(Array): The array to inspect. -
[values]
(...Array): The arrays of values to exclude.
Returns
(Array): Returns the new array of filtered values.
Example
_.difference([1, 2, 3], [4, 2]);
// => [1, 3]
_.drop(array, [n=1])
Creates a slice of array
with n
elements dropped from the beginning.
Arguments
-
array
(Array): The array to query. -
[n=1]
(number): The number of elements to drop.
Returns
(Array): Returns the slice of array
.
Example
_.drop([1, 2, 3]);
// => [2, 3]
_.drop([1, 2, 3], 2);
// => [3]
_.drop([1, 2, 3], 5);
// => []
_.drop([1, 2, 3], 0);
// => [1, 2, 3]
_.dropRight(array, [n=1])
Creates a slice of array
with n
elements dropped from the end.
Arguments
-
array
(Array): The array to query. -
[n=1]
(number): The number of elements to drop.
Returns
(Array): Returns the slice of array
.
Example
_.dropRight([1, 2, 3]);
// => [1, 2]
_.dropRight([1, 2, 3], 2);
// => [1]
_.dropRight([1, 2, 3], 5);
// => []
_.dropRight([1, 2, 3], 0);
// => [1, 2, 3]
_.dropRightWhile(array, [predicate=_.identity], [thisArg])
Creates a slice of array
excluding elements dropped from the end.
Elements are dropped until predicate
returns falsey. The predicate is
bound to thisArg
and invoked with three arguments: (value, index, array).
If a property name is provided for predicate
the created _.property
style callback returns the property value of the given element.
If a value is also provided for thisArg
the created _.matchesProperty
style callback returns true
for elements that have a matching property
value, else false
.
If an object is provided for predicate
the created _.matches
style
callback returns true
for elements that match the properties of the given
object, else false
.
Arguments
-
array
(Array): The array to query. -
[predicate=_.identity]
(Function|Object|string): The function invoked per iteration. -
[thisArg]
(*): Thethis
binding ofpredicate
.
Returns
(Array): Returns the slice of array
.
Example
_.dropRightWhile([1, 2, 3], function(n) {
return n > 1;
});
// => [1]
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': false }
];
// using the `_.matches` callback shorthand
_.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
// => ['barney', 'fred']
// using the `_.matchesProperty` callback shorthand
_.pluck(_.dropRightWhile(users, 'active', false), 'user');
// => ['barney']
// using the `_.property` callback shorthand
_.pluck(_.dropRightWhile(users, 'active'), 'user');
// => ['barney', 'fred', 'pebbles']
_.dropWhile(array, [predicate=_.identity], [thisArg])
Creates a slice of array
excluding elements dropped from the beginning.
Elements are dropped until predicate
returns falsey. The predicate is
bound to thisArg
and invoked with three arguments: (value, index, array).
If a property name is provided for predicate
the created _.property
style callback returns the property value of the given element.
If a value is also provided for thisArg
the created _.matchesProperty
style callback returns true
for elements that have a matching property
value, else false
.
If an object is provided for predicate
the created _.matches
style
callback returns true
for elements that have the properties of the given
object, else false
.
Arguments
-
array
(Array): The array to query. -
[predicate=_.identity]
(Function|Object|string): The function invoked per iteration. -
[thisArg]
(*): Thethis
binding ofpredicate
.
Returns
(Array): Returns the slice of array
.
Example
_.dropWhile([1, 2, 3], function(n) {
return n < 3;
});
// => [3]
var users = [
{ 'user': 'barney', 'active': false },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': true }
];
// using the `_.matches` callback shorthand
_.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
// => ['fred', 'pebbles']
// using the `_.matchesProperty` callback shorthand
_.pluck(_.dropWhile(users, 'active', false), 'user');
// => ['pebbles']
// using the `_.property` callback shorthand
_.pluck(_.dropWhile(users, 'active'), 'user');
// => ['barney', 'fred', 'pebbles']
_.fill(array, value, [start=0], [end=array.length])
Fills elements of array
with value
from start
up to, but not
including, end
.
Note: This method mutates array
.
Arguments
-
array
(Array): The array to fill. -
value
(*): The value to fillarray
with. -
[start=0]
(number): The start position. -
[end=array.length]
(number): The end position.
Returns
(Array): Returns array
.
Example
var array = [1, 2, 3];
_.fill(array, 'a');
console.log(array);
// => ['a', 'a', 'a']
_.fill(Array(3), 2);
// => [2, 2, 2]
_.fill([4, 6, 8], '*', 1, 2);
// => [4, '*', 8]
_.findIndex(array, [predicate=_.identity], [thisArg])
This method is like _.find
except that it returns the index of the first
element predicate
returns truthy for instead of the element itself.
If a property name is provided for predicate
the created _.property
style callback returns the property value of the given element.
If a value is also provided for thisArg
the created _.matchesProperty
style callback returns true
for elements that have a matching property
value, else false
.
If an object is provided for predicate
the created _.matches
style
callback returns true
for elements that have the properties of the given
object, else false
.
Arguments
-
array
(Array): The array to search. -
[predicate=_.identity]
(Function|Object|string): The function invoked per iteration. -
[thisArg]
(*): Thethis
binding ofpredicate
.
Returns
(number): Returns the index of the found element, else -1
.
Example
var users = [
{ 'user': 'barney', 'active': false },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': true }
];
_.findIndex(users, function(chr) {
return chr.user == 'barney';
});
// => 0
// using the `_.matches` callback shorthand
_.findIndex(users, { 'user': 'fred', 'active': false });
// => 1
// using the `_.matchesProperty` callback shorthand
_.findIndex(users, 'active', false);
// => 0
// using the `_.property` callback shorthand
_.findIndex(users, 'active');
// => 2
_.findLastIndex(array, [predicate=_.identity], [thisArg])
This method is like _.findIndex
except that it iterates over elements
of collection
from right to left.
If a property name is provided for predicate
the created _.property
style callback returns the property value of the given element.
If a value is also provided for thisArg
the created _.matchesProperty
style callback returns true
for elements that have a matching property
value, else false
.
If an object is provided for predicate
the created _.matches
style
callback returns true
for elements that have the properties of the given
object, else false
.
Arguments
-
array
(Array): The array to search. -
[predicate=_.identity]
(Function|Object|string): The function invoked per iteration. -
[thisArg]
(*): Thethis
binding ofpredicate
.
Returns
(number): Returns the index of the found element, else -1
.
Example
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': false }
];
_.findLastIndex(users, function(chr) {
return chr.user == 'pebbles';
});
// => 2
// using the `_.matches` callback shorthand
_.findLastIndex(users, { 'user': 'barney', 'active': true });
// => 0
// using the `_.matchesProperty` callback shorthand
_.findLastIndex(users, 'active', false);
// => 2
// using the `_.property` callback shorthand
_.findLastIndex(users, 'active');
// => 0
_.first(array)
Gets the first element of array
.
Aliases
_.head
Arguments
-
array
(Array): The array to query.
Returns
(*): Returns the first element of array
.
Example
_.first([1, 2, 3]);
// => 1
_.first([]);
// => undefined
_.flatten(array, [isDeep])
Flattens a nested array. If isDeep
is true
the array is recursively
flattened, otherwise it is only flattened a single level.
Arguments
-
array
(Array): The array to flatten. -
[isDeep]
(boolean): Specify a deep flatten.
Returns
(Array): Returns the new flattened array.
Example
_.flatten([1, [2, 3, [4]]]);
// => [1, 2, 3, [4]]
// using `isDeep`
_.flatten([1, [2, 3, [4]]], true);
// => [1, 2, 3, 4]
_.flattenDeep(array)
Recursively flattens a nested array.
Arguments
-
array
(Array): The array to recursively flatten.
Returns
(Array): Returns the new flattened array.
Example
_.flattenDeep([1, [2, 3, [4]]]);
// => [1, 2, 3, 4]
_.indexOf(array, value, [fromIndex=0])
Gets the index at which the first occurrence of value
is found in array
using SameValueZero
for equality comparisons. If fromIndex
is negative,
it is used as the offset from the end of array
. If array
is sorted
providing true
for fromIndex
performs a faster binary search.
Note: SameValueZero
comparisons are like strict equality comparisons,
e.g. ===
, except that NaN
matches NaN
. See the
ES spec
for more details.
Arguments
-
array
(Array): The array to search. -
value
(*): The value to search for. -
[fromIndex=0]
(boolean|number): The index to search from ortrue
to perform a binary search on a sorted array.
Returns
(number): Returns the index of the matched value, else -1
.
Example
_.indexOf([1, 2, 1, 2], 2);
// => 1
// using `fromIndex`
_.indexOf([1, 2, 1, 2], 2, 2);
// => 3
// performing a binary search
_.indexOf([1, 1, 2, 2], 2, true);
// => 2
_.initial(array)
Gets all but the last element of array
.
Arguments
-
array
(Array): The array to query.
Returns
(Array): Returns the slice of array
.
Example
_.initial([1, 2, 3]);
// => [1, 2]
_.intersection([arrays])
Creates an array of unique values in all provided arrays using SameValueZero
for equality comparisons.
Note: SameValueZero
comparisons are like strict equality comparisons,
e.g. ===
, except that NaN
matches NaN
. See the
ES spec
for more details.
Arguments
-
[arrays]
(...Array): The arrays to inspect.
Returns
(Array): Returns the new array of shared values.
Example
_.intersection([1, 2], [4, 2], [2, 1]);
// => [2]
_.last(array)
Gets the last element of array
.
Arguments
-
array
(Array): The array to query.
Returns
(*): Returns the last element of array
.
Example
_.last([1, 2, 3]);
// => 3
_.lastIndexOf(array, value, [fromIndex=array.length-1])
This method is like _.indexOf
except that it iterates over elements of
array
from right to left.
Arguments
-
array
(Array): The array to search. -
value
(*): The value to search for. -
[fromIndex=array.length-1]
(boolean|number): The index to search from ortrue
to perform a binary search on a sorted array.
Returns
(number): Returns the index of the matched value, else -1
.
Example
_.lastIndexOf([1, 2, 1, 2], 2);
// => 3
// using `fromIndex`
_.lastIndexOf([1, 2, 1, 2], 2, 2);
// => 1
// performing a binary search
_.lastIndexOf([1, 1, 2, 2], 2, true);
// => 3
_.pull(array, [values])
Removes all provided values from array
using SameValueZero
for equality
comparisons.
Notes:
- Unlike
_.without
, this method mutatesarray
.
* `SameValueZero` comparisons are like strict equality comparisons, e.g. `===`, except that `NaN` matches `NaN`. See the [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) for more details.
Arguments
-
array
(Array): The array to modify. -
[values]
(...*): The values to remove.
Returns
(Array): Returns array
.
Example
var array = [1, 2, 3, 1, 2, 3];
_.pull(array, 2, 3);
console.log(array);
// => [1, 1]
_.pullAt(array, [indexes])
Removes elements from array
corresponding to the given indexes and returns
an array of the removed elements. Indexes may be specified as an array of
indexes or as individual arguments.
Note: Unlike _.at
, this method mutates array
.
Arguments
-
array
(Array): The array to modify. -
[indexes]
(...(number|number[]): The indexes of elements to remove, specified as individual indexes or arrays of indexes.
Returns
(Array): Returns the new array of removed elements.
Example
var array = [5, 10, 15, 20];
var evens = _.pullAt(array, 1, 3);
console.log(array);
// => [5, 15]
console.log(evens);
// => [10, 20]
_.remove(array, [predicate=_.identity], [thisArg])
Removes all elements from array
that predicate
returns truthy for
and returns an array of the removed elements. The predicate is bound to
thisArg
and invoked with three arguments: (value, index, array).
If a property name is provided for predicate
the created _.property
style callback returns the property value of the given element.
If a value is also provided for thisArg
the created _.matchesProperty
style callback returns true
for elements that have a matching property
value, else false
.
If an object is provided for predicate
the created _.matches
style
callback returns true
for elements that have the properties of the given
object, else false
.
Note: Unlike _.filter
, this method mutates array
.
Arguments
-
array
(Array): The array to modify. -
[predicate=_.identity]
(Function|Object|string): The function invoked per iteration. -
[thisArg]
(*): Thethis
binding ofpredicate
.
Returns
(Array): Returns the new array of removed elements.
Example
var array = [1, 2, 3, 4];
var evens = _.remove(array, function(n) {
return n % 2 == 0;
});
console.log(array);
// => [1, 3]
console.log(evens);
// => [2, 4]
_.rest(array)
Gets all but the first element of array
.
Aliases
_.tail
Arguments
-
array
(Array): The array to query.
Returns
(Array): Returns the slice of array
.
Example
_.rest([1, 2, 3]);
// => [2, 3]
_.slice(array, [start=0], [end=array.length])
Creates a slice of array
from start
up to, but not including, end
.
Note: This function is used instead of Array#slice
to support node
lists in IE < 9 and to ensure dense arrays are returned.
Arguments
-
array
(Array): The array to slice. -
[start=0]
(number): The start position. -
[end=array.length]
(number): The end position.
Returns
(Array): Returns the slice of array
.
_.sortedIndex(array, value, [iteratee=_.identity], [thisArg])
Uses a binary search to determine the lowest index at which value
should
be inserted into array
in order to maintain its sort order. If an iteratee
function is provided it is invoked for value
and each element of array
to compute their sort ranking. The iteratee is bound to thisArg
and
invoked with one argument; (value).
If a property name is provided for iteratee
the created _.property
style callback returns the property value of the given element.
If a value is also provided for thisArg
the created _.matchesProperty
style callback returns true
for elements that have a matching property
value, else false
.
If an object is provided for iteratee
the created _.matches
style
callback returns true
for elements that have the properties of the given
object, else false
.
Arguments
-
array
(Array): The sorted array to inspect. -
value
(*): The value to evaluate. -
[iteratee=_.identity]
(Function|Object|string): The function invoked per iteration. -
[thisArg]
(*): Thethis
binding ofiteratee
.
Returns
(number): Returns the index at which value
should be inserted
into array
.
Example
_.sortedIndex([30, 50], 40);
// => 1
_.sortedIndex([4, 4, 5, 5], 5);
// => 2
var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
// using an iteratee function
_.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
return this.data[word];
}, dict);
// => 1
// using the `_.property` callback shorthand
_.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
// => 1
_.sortedLastIndex(array, value, [iteratee=_.identity], [thisArg])
This method is like _.sortedIndex
except that it returns the highest
index at which value
should be inserted into array
in order to
maintain its sort order.
Arguments
-
array
(Array): The sorted array to inspect. -
value
(*): The value to evaluate. -
[iteratee=_.identity]
(Function|Object|string): The function invoked per iteration. -
[thisArg]
(*): Thethis
binding ofiteratee
.
Returns
(number): Returns the index at which value
should be inserted
into array
.
Example
_.sortedLastIndex([4, 4, 5, 5], 5);
// => 4
_.take(array, [n=1])
Creates a slice of array
with n
elements taken from the beginning.
Arguments
-
array
(Array): The array to query. -
[n=1]
(number): The number of elements to take.
Returns
(Array): Returns the slice of array
.
Example
_.take([1, 2, 3]);
// => [1]
_.take([1, 2, 3], 2);
// => [1, 2]
_.take([1, 2, 3], 5);
// => [1, 2, 3]
_.take([1, 2, 3], 0);
// => []
_.takeRight(array, [n=1])
Creates a slice of array
with n
elements taken from the end.
Arguments
-
array
(Array): The array to query. -
[n=1]
(number): The number of elements to take.
Returns
(Array): Returns the slice of array
.
Example
_.takeRight([1, 2, 3]);
// => [3]
_.takeRight([1, 2, 3], 2);
// => [2, 3]
_.takeRight([1, 2, 3], 5);
// => [1, 2, 3]
_.takeRight([1, 2, 3], 0);
// => []
_.takeRightWhile(array, [predicate=_.identity], [thisArg])
Creates a slice of array
with elements taken from the end. Elements are
taken until predicate
returns falsey. The predicate is bound to thisArg
and invoked with three arguments: (value, index, array).
If a property name is provided for predicate
the created _.property
style callback returns the property value of the given element.
If a value is also provided for thisArg
the created _.matchesProperty
style callback returns true
for elements that have a matching property
value, else false
.
If an object is provided for predicate
the created _.matches
style
callback returns true
for elements that have the properties of the given
object, else false
.
Arguments
-
array
(Array): The array to query. -
[predicate=_.identity]
(Function|Object|string): The function invoked per iteration. -
[thisArg]
(*): Thethis
binding ofpredicate
.
Returns
(Array): Returns the slice of array
.
Example
_.takeRightWhile([1, 2, 3], function(n) {
return n > 1;
});
// => [2, 3]
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': false }
];
// using the `_.matches` callback shorthand
_.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
// => ['pebbles']
// using the `_.matchesProperty` callback shorthand
_.pluck(_.takeRightWhile(users, 'active', false), 'user');
// => ['fred', 'pebbles']
// using the `_.property` callback shorthand
_.pluck(_.takeRightWhile(users, 'active'), 'user');
// => []
_.takeWhile(array, [predicate=_.identity], [thisArg])
Creates a slice of array
with elements taken from the beginning. Elements
are taken until predicate
returns falsey. The predicate is bound to
thisArg
and invoked with three arguments: (value, index, array).
If a property name is provided for predicate
the created _.property
style callback returns the property value of the given element.
If a value is also provided for thisArg
the created _.matchesProperty
style callback returns true
for elements that have a matching property
value, else false
.
If an object is provided for predicate
the created _.matches
style
callback returns true
for elements that have the properties of the given
object, else false
.
Arguments
-
array
(Array): The array to query. -
[predicate=_.identity]
(Function|Object|string): The function invoked per iteration. -
[thisArg]
(*): Thethis
binding ofpredicate
.
Returns
(Array): Returns the slice of array
.
Example
_.takeWhile([1, 2, 3], function(n) {
return n < 3;
});
// => [1, 2]
var users = [
{ 'user': 'barney', 'active': false },
{ 'user': 'fred', 'active': false},
{ 'user': 'pebbles', 'active': true }
];
// using the `_.matches` callback shorthand
_.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
// => ['barney']
// using the `_.matchesProperty` callback shorthand
_.pluck(_.takeWhile(users, 'active', false), 'user');
// => ['barney', 'fred']
// using the `_.property` callback shorthand
_.pluck(_.takeWhile(users, 'active'), 'user');
// => []
_.union([arrays])
Creates an array of unique values, in order, of the provided arrays using
SameValueZero
for equality comparisons.
Note: SameValueZero
comparisons are like strict equality comparisons,
e.g. ===
, except that NaN
matches NaN
. See the
ES spec
for more details.
Arguments
-
[arrays]
(...Array): The arrays to inspect.
Returns
(Array): Returns the new array of combined values.
Example
_.union([1, 2], [4, 2], [2, 1]);
// => [1, 2, 4]
_.uniq(array, [isSorted], [iteratee], [thisArg])
Creates a duplicate-value-free version of an array using SameValueZero
for equality comparisons. Providing true
for isSorted
performs a faster
search algorithm for sorted arrays. If an iteratee function is provided it
is invoked for each value in the array to generate the criterion by which
uniqueness is computed. The iteratee
is bound to thisArg
and invoked
with three arguments: (value, index, array).
If a property name is provided for iteratee
the created _.property
style callback returns the property value of the given element.
If a value is also provided for thisArg
the created _.matchesProperty
style callback returns true
for elements that have a matching property
value, else false
.
If an object is provided for iteratee
the created _.matches
style
callback returns true
for elements that have the properties of the given
object, else false
.
Note: SameValueZero
comparisons are like strict equality comparisons,
e.g. ===
, except that NaN
matches NaN
. See the
ES spec
for more details.
Aliases
_.unique
Arguments
-
array
(Array): The array to inspect. -
[isSorted]
(boolean): Specify the array is sorted. -
[iteratee]
(Function|Object|string): The function invoked per iteration. -
[thisArg]
(*): Thethis
binding ofiteratee
.
Returns
(Array): Returns the new duplicate-value-free array.
Example
_.uniq([1, 2, 1]);
// => [1, 2]
// using `isSorted`
_.uniq([1, 1, 2], true);
// => [1, 2]
// using an iteratee function
_.uniq([1, 2.5, 1.5, 2], function(n) {
return this.floor(n);
}, Math);
// => [1, 2.5]
// using the `_.property` callback shorthand
_.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }, { 'x': 2 }]
_.unzip(array)
This method is like _.zip
except that it accepts an array of grouped
elements and creates an array regrouping the elements to their pre-_.zip
configuration.
Arguments
-
array
(Array): The array of grouped elements to process.
Returns
(Array): Returns the new array of regrouped elements.
Example
var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
// => [['fred', 30, true], ['barney', 40, false]]
_.unzip(zipped);
// => [['fred', 'barney'], [30, 40], [true, false]]
_.without(array, [values])
Creates an array excluding all provided values using SameValueZero
for
equality comparisons.
Note: SameValueZero
comparisons are like strict equality comparisons,
e.g. ===
, except that NaN
matches NaN
. See the
ES spec
for more details.
Arguments
-
array
(Array): The array to filter. -
[values]
(...*): The values to exclude.
Returns
(Array): Returns the new array of filtered values.
Example
_.without([1, 2, 1, 3], 1, 2);
// => [3]
_.xor([arrays])
Creates an array that is the symmetric difference of the provided arrays. See Wikipedia for more details.
Arguments
-
[arrays]
(...Array): The arrays to inspect.
Returns
(Array): Returns the new array of values.
Example
_.xor([1, 2], [4, 2]);
// => [1, 4]
_.zip([arrays])
Creates an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.
Arguments
-
[arrays]
(...Array): The arrays to process.
Returns
(Array): Returns the new array of grouped elements.
Example
_.zip(['fred', 'barney'], [30, 40], [true, false]);
// => [['fred', 30, true], ['barney', 40, false]]
_.zipObject(props, [values=[]])
The inverse of _.pairs
; this method returns an object composed from arrays
of property names and values. Provide either a single two dimensional array,
e.g. [[key1, value1], [key2, value2]]
or two arrays, one of property names
and one of corresponding values.
Aliases
_.object
Arguments
-
props
(Array): The property names. -
[values=[]]
(Array): The property values.
Returns
(Object): Returns the new object.
Example
_.zipObject([['fred', 30], ['barney', 40]]);
// => { 'fred': 30, 'barney': 40 }
_.zipObject(['fred', 'barney'], [30, 40]);
// => { 'fred': 30, 'barney': 40 }
“Chain” Methods
_(value)
Creates a lodash
object which wraps value
to enable implicit chaining.
Methods that operate on and return arrays, collections, and functions can
be chained together. Methods that return a boolean or single value will
automati