This site has moved.
Your Google Script tool kit with more than 40 methods. This library helps you write less code by adding tons of helper methods.
Installing the underscoreGS Library
1. In the script editor, click on Resources > Manage librairies...
2. In the Included Libraries window, insert the project key into the Find a Library textbox and click on the Select button.
Project Key: MiC3qjLYVUjCCUQpMqPPTWUF7jOZt2NQ8
3. Select the Stable version from the drop down list.
*Note that the Identifier is how you call the library.
Clicking the blue "Title" link will bring up the documentation window.
4. In your code type: UnderscoreGS.
You will see the available choices in the autocomplete box.
Using the Library
Lets say you have a list of numbers that you would like to randomize [1,2,3,4,5,6,7,8,9].
The _shuffle method will work perfectly for this task.
Simply pass the original array through the method.
The resulting array will be randomized: [4, 1, 8, 5, 2, 9, 7, 3, 6]
EXAMPLE
function myFunction() {
var sortedOut = [1,2,3,4,5,6,7,8,9];
var mixedUp = UnderscoreGS._shuffle(sortedOut);
Logger.log(mixedUp);
}
Reference Documentation
Iterates over a list of elements, yielding each in turn to an iterator function.
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.
Produces a new array of values by mapping each value in list through a transformation function (iterator)
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.
Looks through each value in the list, returning an array of all the values that pass a truth test (iterator)
Returns the values in list without the elements that the truth test (iterator) passes. The opposite of filter.
Returns true if all of the values in the list pass the iterator truth test.
Returns true if the value is present in the list, using === to test equality. Uses indexOf internally, if list is an Array.
A convenient version of what is perhaps the most common use-case for map: extracting a list of property values.
Returns a sorted copy of list, ranked in ascending order by the results of running each value through iterator.
Return the maximum element (or element-based computation).
Return the minimum element (or element-based computation).
Returns a shuffled copy of the list, using a version of the Fisher-Yates shuffle
Name
obj
Type
Array
Description
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.
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.
Converts the list (anything that can be iterated over), into a real Array. Useful for transmuting the arguments object.
Name
iterable
Type
Iterable
Description
Return the number of values in the list.
Name
obj
Type
Object
Description
Get the first element of an array. Passing n will return the first N values in the array.
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.
Get the Last element of an array. Passing n will return the Last N values in the array.
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.
Type
Integer
Description
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.
Type
Object
Description
Retrieve all the names of the object's properties.
Name
obj
Type
Object
Description
Type
String[]
Description
Return all of the values of the object's properties.
Name
obj
Type
Object
Description
Type
Object[]
Description
Return all of the values of the object's methods.
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object contains no values.
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object is a DOM element.
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object is an Array.
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object is an Object.
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object is a Function.
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object is a String.
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object is a Number (including NaN).
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object is a Boolean.
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object is a Date.
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object is a RegExp.
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object is null.
Name
obj
Type
Object
Description
Type
Boolean
Description
Returns true if object is undefined.
Name
obj
Type
Object
Description
Type
Boolean
Description
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.
Name
value
Type
Description
Returns a random string of upper and lower case letters and numbers
Name
length
Type
Integer
Description
Type
String
Description
Removes whitespace around a string
Name
str
Type
String
Description
Type
String
Description
Returns all the keys in a given JSON object. Will recurse through all Arrays and Objects
Name
json
Type
Object
Description
A JSON Object
Type
String
Description
keys in object