Lets say you have a list of numbers that you would like to randomize [1,2,3,4,5,6,7,8,9].
Contents
- 1 _each(Object obj, Iterator iterator, context)
- 1.1 Arguments:
- 1.2 _any(Object obj, Iterator iterator, context)
- 1.3 _map(Object obj, Iterator iterator, context)
- 1.4 _find(Array obj, Iterator iterator, context)
- 1.5 _filter(Array obj, Iterator iterator, context)
- 1.6 _reject(Array obj, Iterator iterator, context)
- 1.7 _all(Array obj, Iterator iterator, context)
- 1.8 _contains(Array obj, Target target)
- 1.9 _pluck(Object obj, String key)
- 1.10 _sortBy(Array obj, Iterator iterator, context)
- 1.11 _max( List, Iterator iterator, context)
- 1.12 _min(Object obj, Iterator iterator, context)
- 1.13 _shuffle(Array obj)
- 1.14 _groupBy(Array obj, Iterator val)
- 1.15 _sortedIndex( array, Object obj, Iterator iterator)
- 1.16 _toArray(Iterable iterable)
- 1.17 _size(Object obj)
- 1.18 _first(Array array, Integer n, guard)
- 1.19 _initial(Array array, Integer n, guard)
- 1.20 _last(Array array, Integer n, guard)
- 1.21 _tail( array, index, guard)
- 1.22 _indexOf(Array array, Item item, Boolean isSorted)
- 1.23 _lastIndexOf(Array array, Item item)
- 1.24 _keys(Object obj)
- 1.25 _values(Object obj)
- 1.26 _methods(Object obj)
- 1.27 _isEmpty(Object obj)
- 1.28 _isElement(Object obj)
- 1.29 _isArray(Object obj)
- 1.30 _isObject(Object obj)
- 1.31 _isFunction(Object obj)
- 1.32 _isString(Object obj)
- 1.33 _has( obj, key)
- 1.34 _isNumber(Object obj)
- 1.35 _isBoolean(Object obj)
- 1.36 _isDate(Object obj)
- 1.37 _isRegExp(Object obj)
- 1.38 _isNull(Object obj)
- 1.39 _isUndefined(Object obj)
- 1.40 _identity( value)
- 1.41 _randomString(Integer length)
- 1.42 _trim(String str)
- 1.43 _recurseJSON(Object json)
_each(Object obj, Iterator iterator, context)
Iterates over a list of elements, yielding each in turn to an iterator function.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
iterator |
Iterator |
|
context |
|
|
_any(Object obj, Iterator iterator, context)
Determine if at least one element in the object matches a truth test. Delegates to ECMAScript 5's native some if available. Aliased as any.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
iterator |
Iterator |
|
context |
|
|
_map(Object obj, Iterator iterator, context)
Produces a new array of values by mapping each value in list through a transformation function (iterator)
Arguments:
Name |
Type |
Description |
obj |
Object |
|
iterator |
Iterator |
|
context |
|
|
_find(Array obj, Iterator iterator, context)
Looks through each value in the list, returning the first one that passes a truth test (iterator). The function returns as soon as it finds an acceptable element, and doesn't traverse the entire list.
Arguments:
Name |
Type |
Description |
obj |
Array |
|
iterator |
Iterator |
|
context |
|
|
_filter(Array obj, Iterator iterator, context)
Looks through each value in the list, returning an array of all the values that pass a truth test (iterator)
Arguments:
Name |
Type |
Description |
obj |
Array |
|
iterator |
Iterator |
|
context |
|
|
_reject(Array obj, Iterator iterator, context)
Returns the values in list without the elements that the truth test (iterator) passes. The opposite of filter.
Arguments:
Name |
Type |
Description |
obj |
Array |
|
iterator |
Iterator |
|
context |
|
|
_all(Array obj, Iterator iterator, context)
Returns true if all of the values in the list pass the iterator truth test.
Arguments:
Name |
Type |
Description |
obj |
Array |
|
iterator |
Iterator |
|
context |
|
|
_contains(Array obj, Target target)
Returns true if the value is present in the list, using === to test equality. Uses indexOf internally, if list is an Array.
Arguments:
Name |
Type |
Description |
obj |
Array |
|
target |
Target |
|
_pluck(Object obj, String key)
A convenient version of what is perhaps the most common use-case for map: extracting a list of property values.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
key |
String |
|
_sortBy(Array obj, Iterator iterator, context)
Returns a sorted copy of list, ranked in ascending order by the results of running each value through iterator.
Arguments:
Name |
Type |
Description |
obj |
Array |
|
iterator |
Iterator |
|
context |
|
|
_max( List, Iterator iterator, context)
Return the maximum element (or element-based computation).
Arguments:
Name |
Type |
Description |
List |
|
|
iterator |
Iterator |
|
context |
|
|
_min(Object obj, Iterator iterator, context)
Return the minimum element (or element-based computation).
Arguments:
Name |
Type |
Description |
obj |
Object |
|
iterator |
Iterator |
|
context |
|
|
_shuffle(Array obj)
Returns a shuffled copy of the list, using a version of the Fisher-Yates shuffle
Arguments:
Name |
Type |
Description |
obj |
Array |
|
_groupBy(Array obj, Iterator val)
Splits a collection into sets, grouped by the result of running each value through iterator. If iterator is a string instead of a function, groups by the property named by iterator on each of the values.
Arguments:
Name |
Type |
Description |
obj |
Array |
|
val |
Iterator |
|
_sortedIndex( array, Object obj, Iterator iterator)
Uses a binary search to determine the index at which the value should be inserted into the list in order to maintain the list's sorted order. If an iterator is passed, it will be used to compute the sort ranking of each value.
Arguments:
Name |
Type |
Description |
array |
|
|
obj |
Object |
|
iterator |
Iterator |
|
_toArray(Iterable iterable)
Converts the list (anything that can be iterated over), into a real Array. Useful for transmuting the arguments object.
Arguments:
Name |
Type |
Description |
iterable |
Iterable |
|
_size(Object obj)
Return the number of values in the list.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
_first(Array array, Integer n, guard)
Get the first element of an array. Passing n will return the first N values in the array.
Arguments:
Name |
Type |
Description |
array |
Array |
|
n |
Integer |
|
guard |
|
|
_initial(Array array, Integer n, guard)
Returns everything but the last entry of the array. Especially useful on the arguments object. Pass n to exclude the last n elements from the result.
Arguments:
Name |
Type |
Description |
array |
Array |
|
n |
Integer |
|
guard |
|
|
_last(Array array, Integer n, guard)
Get the Last element of an array. Passing n will return the Last N values in the array.
Arguments:
Name |
Type |
Description |
array |
Array |
|
n |
Integer |
|
guard |
|
|
_tail( array, index, guard)
Arguments:
Name |
Type |
Description |
array |
|
|
index |
|
|
guard |
|
|
_indexOf(Array array, Item item, Boolean isSorted)
Returns the index at which value can be found in the array, or -1 if value is not present in the array. Uses the native indexOf function unless it's missing. If you're working with a large array, and you know that the array is already sorted, pass true for isSorted to use a faster binary search.
Arguments:
Name |
Type |
Description |
array |
Array |
|
item |
Item |
|
isSorted |
Boolean |
|
Return Values:
_lastIndexOf(Array array, Item item)
Returns the index of the last occurrence of value in the array, or -1 if value is not present. Uses the native lastIndexOf function if possible.
Arguments:
Name |
Type |
Description |
array |
Array |
|
item |
Item |
|
Return Values:
_keys(Object obj)
Retrieve all the names of the object's properties.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
Type |
Description |
String[] |
|
_values(Object obj)
Return all of the values of the object's properties.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
Type |
Description |
Object[] |
|
_methods(Object obj)
Return all of the values of the object's methods.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_isEmpty(Object obj)
Returns true if object contains no values.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_isElement(Object obj)
Returns true if object is a DOM element.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_isArray(Object obj)
Returns true if object is an Array.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_isObject(Object obj)
Returns true if object is an Object.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_isFunction(Object obj)
Returns true if object is a Function.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_isString(Object obj)
Returns true if object is a String.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_has( obj, key)
Arguments:
Name |
Type |
Description |
obj |
|
|
key |
|
|
_isNumber(Object obj)
Returns true if object is a Number (including NaN).
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_isBoolean(Object obj)
Returns true if object is a Boolean.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_isDate(Object obj)
Returns true if object is a Date.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_isRegExp(Object obj)
Returns true if object is a RegExp.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_isNull(Object obj)
Returns true if object is null.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_isUndefined(Object obj)
Returns true if object is undefined.
Arguments:
Name |
Type |
Description |
obj |
Object |
|
Return Values:
_identity( value)
Returns the same value that is used as the argument. In math: f(x) = x This function looks useless, but is used throughout Underscore as a default iterator.
Arguments:
Name |
Type |
Description |
value |
|
|
_randomString(Integer length)
Returns a random string of upper and lower case letters and numbers
Arguments:
Name |
Type |
Description |
length |
Integer |
|
Return Values:
_trim(String str)
Removes whitespace around a string
Arguments:
Name |
Type |
Description |
str |
String |
|
Return Values:
_recurseJSON(Object json)
Returns all the keys in a given JSON object. Will recurse through all Arrays and Objects
Arguments:
Name |
Type |
Description |
json |
Object |
A JSON Object |
Return Values:
Type |
Description |
String |
keys in object |