### Install Lodash via npm Source: https://lodash.com/ Install Lodash globally and then as a project dependency using npm. ```bash $ npm i -g npm $ npm i --save lodash ``` -------------------------------- ### Install lodash-cli Globally Source: https://lodash.com/custom-builds Install the lodash-cli globally to use its command-line interface for custom builds. This command installs the package and makes the `lodash` command available in your terminal. ```bash $ npm i -g lodash-cli $ lodash -h ``` -------------------------------- ### _.fill Examples Source: https://lodash.com/docs Fills elements of an array with a specified value within a given range. This method mutates the original array. Default start is 0 and end is array length. ```javascript 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, 10], '*', 1, 3); // => [4, '*', '*', 10] ``` -------------------------------- ### Take elements from beginning Source: https://lodash.com/docs Creates a slice of an array with n elements taken from the start. ```javascript _.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); // => [] ``` -------------------------------- ### _.sample(collection) Source: https://lodash.com/docs Gets a random element from a collection (Array or Object). ```APIDOC ## _.sample(collection) ### Description Gets a random element from `collection`. ### Arguments 1. `collection` _(Array|Object)_ : The collection to sample. ### Returns _(*)_ : Returns the random element. ### Example ```javascript _.sample([1, 2, 3, 4]); // => 2 ``` ``` -------------------------------- ### Pad start of a string Source: https://lodash.com/docs Pads a string on the left side to reach a specified length. ```javascript _.padStart('abc', 6); // => '   abc'   _.padStart('abc', 6, '_-'); // => '_-_abc'   _.padStart('abc', 3); // => 'abc' ``` -------------------------------- ### _.head Source: https://lodash.com/docs Gets the first element of an array. ```APIDOC ## _.head(array) ### Description Gets the first element of array. ### Parameters #### Arguments - **array** (Array) - Required - The array to query. ### Returns - **element** (*) - Returns the first element of array. ``` -------------------------------- ### Lodash Partition Example Source: https://lodash.com/ Use _.partition to split elements into two groups based on the return value of the predicate function. ```javascript _.partition([1, 2, 3, 4], n => n % 2); // → [[1, 3], [2, 4]] ``` -------------------------------- ### Lodash Plant Example Source: https://lodash.com/docs Demonstrates creating a clone of a chain sequence by planting a new value using the `plant` method. The original sequence remains unchanged. ```javascript function square(n) {   return n * n; } var wrapped = _([1, 2]).map(square); var other = wrapped.plant([3, 4]); other.value(); // => [9, 16] wrapped.value(); // => [1, 4] ``` -------------------------------- ### _.union Example Source: https://lodash.com/docs Creates an array of unique values from multiple arrays. ```javascript _.union([2], [1, 2]); // => [2, 1] ``` -------------------------------- ### _.unionBy Example Source: https://lodash.com/docs Creates an array of unique values by applying an iteratee to each element before comparison. ```javascript _.unionBy([2.1], [1.2, 2.3], Math.floor); // => [2.1, 1.2] // The `_.property` iteratee shorthand. _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); // => [{ 'x': 1 }, { 'x': 2 }] ``` -------------------------------- ### Lodash Iterator Protocol Example Source: https://lodash.com/docs Shows how to use the `next` method to get the next value on a wrapped object following the iterator protocol. ```javascript var wrapped = _([1, 2]); wrapped.next(); // => { 'done': false, 'value': 1 }  wrapped.next(); // => { 'done': false, 'value': 2 }  wrapped.next(); // => { 'done': true, 'value': undefined } ``` -------------------------------- ### Lodash Chaining Example Source: https://lodash.com/docs Demonstrates how to use Lodash for data manipulation with and without explicit chaining. ```javascript var users = [    { 'user': 'barney', 'age': 36 },    { 'user': 'fred',  'age':  40 }  ];  // A sequence without explicit chaining. _( users ).head(); // => { 'user': 'barney', 'age':  36 }  // A sequence with explicit chaining. _( users )   .chain()   .head()   .pick('user')   .value(); // => { 'user': 'barney' } ``` -------------------------------- ### _.findIndex Example Source: https://lodash.com/docs Finds the index of the first element in an array that satisfies a given predicate function. Returns -1 if no element is found. The search can start from a specified index. ```javascript This method is like `_.find` except that it returns the index of the first element `predicate` returns truthy for instead of the element itself. #### Since 1.1.0 #### Arguments 1. `array` _(Array)_ : The array to inspect. 2. `[predicate=_.identity]` _(Function)_ : The function invoked per iteration. 3. `[fromIndex=0]` _(number)_ : The index to search from. #### Returns _(number)_ : Returns the index of the found element, else `-1`. ``` -------------------------------- ### _.drop Examples Source: https://lodash.com/docs Creates a slice of an array with a specified number of elements removed from the beginning. If n is 0, the original array is returned. If n is greater than the array length, an empty array is returned. ```javascript _.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] ``` -------------------------------- ### _.takeWhile Example Source: https://lodash.com/docs Takes elements from the beginning of an array while the predicate returns truthy. Supports various predicate shorthands. ```javascript var users = [ { 'user': 'barney', 'active': false }, { 'user': 'fred', 'active': false }, { 'user': 'pebbles', 'active': true } ]; _.takeWhile(users, function(o) { return !o.active; }); // => objects for ['barney', 'fred'] // The `_.matches` iteratee shorthand. _.takeWhile(users, { 'user': 'barney', 'active': false }); // => objects for ['barney'] // The `_.matchesProperty` iteratee shorthand. _.takeWhile(users, ['active', false]); // => objects for ['barney', 'fred'] // The `_.property` iteratee shorthand. _.takeWhile(users, 'active'); // => [] ``` -------------------------------- ### _.unionWith Example Source: https://lodash.com/docs Creates an array of unique values by comparing elements using a custom comparator function. ```javascript var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; _.unionWith(objects, others, _.isEqual); // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] ``` -------------------------------- ### _.sampleSize(collection, [n=1]) Source: https://lodash.com/docs Gets `n` random elements at unique keys from `collection` up to the size of `collection`. ```APIDOC ## _.sampleSize(collection, [n=1]) ### Description Gets `n` random elements at unique keys from `collection` up to the size of `collection`. ### Arguments 1. `collection` _(Array|Object)_ : The collection to sample. 2. `[n=1]` _(number)_ : The number of elements to sample. ### Returns _(Array)_ : Returns the random elements. ### Example ```javascript _.sampleSize([1, 2, 3], 2); // => [3, 1] _.sampleSize([1, 2, 3], 4); // => [2, 3, 1] ``` ``` -------------------------------- ### _.uniq Example Source: https://lodash.com/docs Creates a duplicate-free version of an array, keeping only the first occurrence of each element. ```javascript _.uniq([2, 1, 2]); // => [2, 1] ``` -------------------------------- ### _.uniqBy Example Source: https://lodash.com/docs Creates a duplicate-free version of an array by applying an iteratee to each element before comparison. ```javascript _.uniqBy([2.1, 1.2, 2.3], Math.floor); // => [2.1, 1.2] // The `_.property` iteratee shorthand. _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); // => [{ 'x': 1 }, { 'x': 2 }] ``` -------------------------------- ### String Case Conversion and Manipulation Source: https://lodash.com/docs Functions for converting strings to snake_case, startCase, and checking if a string starts with a specific target. ```APIDOC ## _.snakeCase([string='']) ### Description Converts `string` to snake case. ### Method N/A (Utility Function) ### Endpoint N/A (Utility Function) ### Parameters #### Arguments - **string** (string) - Optional - The string to convert. Defaults to an empty string. ### Returns _(string)_ : Returns the snake cased string. ### Example ```javascript _.snakeCase('Foo Bar'); // => 'foo_bar'   _.snakeCase('fooBar'); // => 'foo_bar'   _.snakeCase('--FOO-BAR--'); // => 'foo_bar' ``` ## _.split([string=''], separator, [limit]) ### Description Splits `string` by `separator`. This method is based on `String#split`. ### Method N/A (Utility Function) ### Endpoint N/A (Utility Function) ### Parameters #### Arguments - **string** (string) - Optional - The string to split. Defaults to an empty string. - **separator** (RegExp|string) - Required - The separator pattern to split by. - **limit** (number) - Optional - The length to truncate results to. ### Returns _(Array)_ : Returns the string segments. ### Example ```javascript _.split('a-b-c', '-', 2); // => ['a', 'b'] ``` ## _.startCase([string='']) ### Description Converts `string` to start case. ### Method N/A (Utility Function) ### Endpoint N/A (Utility Function) ### Parameters #### Arguments - **string** (string) - Optional - The string to convert. Defaults to an empty string. ### Returns _(string)_ : Returns the start cased string. ### Example ```javascript _.startCase('--foo-bar--'); // => 'Foo Bar'   _.startCase('fooBar'); // => 'Foo Bar'   _.startCase('__FOO_BAR__'); // => 'FOO BAR' ``` ## _.startsWith([string=''], [target], [position=0]) ### Description Checks if `string` starts with the given target string. ### Method N/A (Utility Function) ### Endpoint N/A (Utility Function) ### Parameters #### Arguments - **string** (string) - Optional - The string to inspect. Defaults to an empty string. - **target** (string) - Optional - The string to search for. - **position** (number) - Optional - The position to search from. Defaults to 0. ### Returns _(boolean)_ : Returns `true` if `string` starts with `target`, else `false`. ### Example ```javascript _.startsWith('abc', 'a'); // => true   _.startsWith('abc', 'b'); // => false   _.startsWith('abc', 'b', 1); // => true ``` ``` -------------------------------- ### _.range([start=0], end, [step=1]) Source: https://lodash.com/docs Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end. ```APIDOC ## _.range([start=0], end, [step=1]) ### Description Creates an array of numbers _(positive and/or negative)_ progressing from `start` up to, but not including, `end`. A step of `-1` is used if a negative `start` is specified without an `end` or `step`. If `end` is not specified, it's set to `start` with `start` then set to `0`. **Note:** JavaScript follows the IEEE-754 standard for resolving floating-point values which can produce unexpected results. ### Method Function ### Endpoint N/A (Utility Function) ### Parameters #### Arguments - **[start=0]** (number) - Optional - The start of the range. - **end** (number) - Required - The end of the range. - **[step=1]** (number) - Optional - The value to increment or decrement by. ### Returns - **Array** - Returns the range of numbers. ### Example ```javascript _.range(4); // => [0, 1, 2, 3] _.range(-4); // => [0, -1, -2, -3] _.range(1, 5); // => [1, 2, 3, 4] _.range(0, 20, 5); // => [0, 5, 10, 15] _.range(0, -4, -1); // => [0, -1, -2, -3] _.range(1, 4, 0); // => [1, 1, 1] _.range(0); // => [] ``` ``` -------------------------------- ### _.rest(func, [start=func.length-1]) Source: https://lodash.com/docs Creates a function that invokes the original function with arguments from a specified start position onwards, collected into an array. ```APIDOC ## _.rest(func, [start=func.length-1]) ### Description Creates a function that invokes `func` with the `this` binding of the created function and arguments from `start` and beyond provided as an array. This method is based on the rest parameter. ### Arguments 1. `func` (Function): The function to apply a rest parameter to. 2. `[start=func.length-1]` (number): The start position of the rest parameter. ### Returns (Function): Returns the new function. ### Example ```javascript var say = _.rest(function(what, names) { return what + ' ' + _.initial(names).join(', ') + (_.size(names) > 1 ? ', & ' : '') + _.last(names); }); say('hello', 'fred', 'barney', 'pebbles'); // => 'hello fred, barney, & pebbles' ``` ``` -------------------------------- ### Get own and inherited keys with _.keysIn Source: https://lodash.com/docs Returns an array of an object's own and inherited enumerable property names. ```javascript function Foo() {   this.a = 1;   this.b = 2; }   Foo.prototype.c = 3;   _.keysIn(new Foo); // => ['a', 'b', 'c'] (iteration order is not guaranteed) ``` -------------------------------- ### _.dropRight Examples Source: https://lodash.com/docs Creates a slice of an array with a specified number of elements removed from the end. If n is 0, the original array is returned. If n is greater than the array length, an empty array is returned. ```javascript _.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] ``` -------------------------------- ### _.dropWhile Examples Source: https://lodash.com/docs Creates a slice of an array excluding elements from the beginning until a predicate returns falsey. Supports various predicate shorthands like `_.matches`, `_.matchesProperty`, and `_.property`. ```javascript var users = [ { 'user': 'barney', 'active': false }, { 'user': 'fred', 'active': false }, { 'user': 'pebbles', 'active': true } ]; _.dropWhile(users, function(o) { return !o.active; }); // => objects for ['pebbles'] // The `_.matches` iteratee shorthand. _.dropWhile(users, { 'user': 'barney', 'active': false }); // => objects for ['fred', 'pebbles'] // The `_.matchesProperty` iteratee shorthand. _.dropWhile(users, ['active', false]); // => objects for ['pebbles'] // The `_.property` iteratee shorthand. _.dropWhile(users, 'active'); // => objects for ['barney', 'fred', 'pebbles'] ``` -------------------------------- ### Get property value with _.get Source: https://lodash.com/docs Retrieves the value at a given path of an object, optionally providing a default value. ```javascript var object = { 'a': [{ 'b': { 'c': 3 } }] };   _.get(object, 'a[0].b.c'); // => 3   _.get(object, ['a', '0', 'b', 'c']); // => 3   _.get(object, 'a.b.c', 'default'); // => 'default' ``` -------------------------------- ### Display Help Information Source: https://lodash.com/custom-builds Show the help information for the lodash-cli, listing all available commands and options. Use the `-h` or `--help` flag. ```bash -h ``` -------------------------------- ### Get values at specific paths with `_.prototype.at()` Source: https://lodash.com/docs The `at` method on a wrapper object is the wrapper version of `_.at`. It retrieves the values at the specified property paths from the wrapped object. ```javascript var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };   _(object).at(['a[0].b.c', 'a[1]']).value(); // => [3, 4] ``` -------------------------------- ### _.take Source: https://lodash.com/docs Creates a slice of an array with n elements taken from the beginning. ```APIDOC ## _.take(array, [n=1]) ### Description Creates a slice of array with n elements taken from the beginning. ### Parameters #### Arguments - **array** (Array) - Required - The array to query. - **[n=1]** (number) - Optional - The number of elements to take. ### Response - **Returns** (Array) - Returns the slice of array. ``` -------------------------------- ### Specify Output Path Source: https://lodash.com/custom-builds Write the build output to a specific file path or filename. Use the `-o` or `--output` flag. ```bash -o ``` -------------------------------- ### Get the current timestamp Source: https://lodash.com/docs Use `_.now` to get the number of milliseconds elapsed since the Unix epoch. Available since Lodash 2.4.0. ```javascript _.defer(function(stamp) { console.log(_.now() - stamp); }, _.now()); // => Logs the number of milliseconds it took for the deferred invocation. ``` -------------------------------- ### _.differenceWith Example Source: https://lodash.com/docs Calculates the difference between two arrays using a custom comparator function. Use `_.isEqual` for deep object comparison. ```javascript var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual); // => [{ 'x': 2, 'y': 1 }] ``` -------------------------------- ### Create a function with rest parameters using _.rest Source: https://lodash.com/docs _.rest creates a function that accepts arguments from a specified start position as an array. This is useful for functions that need to handle a variable number of trailing arguments. ```javascript var say = _.rest(function(what, names) { return what + ' ' + _.initial(names).join(', ') + (_.size(names) > 1 ? ', & ' : '') + _.last(names); }); say('hello', 'fred', 'barney', 'pebbles'); // => 'hello fred, barney, & pebbles' ``` -------------------------------- ### Check if String Starts With Target using Lodash Source: https://lodash.com/docs The `_.startsWith` function checks if a string begins with a specified target string. An optional position can be provided to start the search from. ```javascript _.startsWith('abc', 'a'); // => true   _.startsWith('abc', 'b'); // => false   _.startsWith('abc', 'b', 1); // => true ``` -------------------------------- ### Write Output to Standard Output Source: https://lodash.com/custom-builds Redirect the build output to standard output instead of writing to a file. Use the `-c` or `--stdout` flag. ```bash -c ``` -------------------------------- ### _.dropRightWhile Examples Source: https://lodash.com/docs Creates a slice of an array excluding elements from the end until a predicate returns falsey. Supports various predicate shorthands like `_.matches`, `_.matchesProperty`, and `_.property`. ```javascript var users = [ { 'user': 'barney', 'active': true }, { 'user': 'fred', 'active': false }, { 'user': 'pebbles', 'active': false } ]; _.dropRightWhile(users, function(o) { return !o.active; }); // => objects for ['barney'] // The `_.matches` iteratee shorthand. _.dropRightWhile(users, { 'user': 'pebbles', 'active': false }); // => objects for ['barney', 'fred'] // The `_.matchesProperty` iteratee shorthand. _.dropRightWhile(users, ['active', false]); // => objects for ['barney'] // The `_.property` iteratee shorthand. _.dropRightWhile(users, 'active'); // => objects for ['barney', 'fred', 'pebbles'] ``` -------------------------------- ### Convert String to Start Case with Lodash Source: https://lodash.com/docs Use `_.startCase` to convert strings into start case format (e.g., 'Foo Bar'). It handles various input formats including hyphens, underscores, and camelCase. ```javascript _.startCase('--foo-bar--'); // => 'Foo Bar'   _.startCase('fooBar'); // => 'Foo Bar'   _.startCase('__FOO_BAR__'); // => 'FOO BAR' ``` -------------------------------- ### Lodash Commit Example Source: https://lodash.com/docs Demonstrates the `commit` method to execute a chain sequence and return the wrapped result. Note that `commit` mutates the original array. ```javascript var array = [1, 2]; var wrapped = _( array ).push(3); console.log(array); // => [1, 2] wrapped = wrapped.commit(); console.log(array); // => [1, 2, 3] wrapped.last(); // => 3 console.log(array); // => [1, 2, 3] ``` -------------------------------- ### _.bindKey(object, key, [partials]) Source: https://lodash.com/docs Creates a function that invokes the method at object[key] with partials prepended to the arguments. ```APIDOC ## _.bindKey(object, key, [partials]) ### Description Creates a function that invokes the method at object[key] with partials prepended to the arguments it receives. This method allows bound functions to reference methods that may be redefined. ### Parameters - **object** (Object) - Required - The object to invoke the method on. - **key** (string) - Required - The key of the method. - **partials** (...*) - Optional - The arguments to be partially applied. ### Response - **Returns** (Function) - Returns the new bound function. ``` -------------------------------- ### _.last Source: https://lodash.com/docs Gets the last element of an array. ```APIDOC ## _.last(array) ### Description Gets the last element of array. ### Parameters - **array** (Array) - Required - The array to query. ### Response - **Returns** (*) - Returns the last element of array. ``` -------------------------------- ### _.initial Source: https://lodash.com/docs Gets all but the last element of an array. ```APIDOC ## _.initial(array) ### Description Gets all but the last element of array. ### Parameters #### Arguments - **array** (Array) - Required - The array to query. ### Returns - **array** (Array) - Returns the slice of array. ``` -------------------------------- ### Get multiple random elements from a collection Source: https://lodash.com/docs Use `_.sampleSize` to get a specified number of unique random elements from a collection. If `n` is greater than the collection size, all elements are returned in a shuffled order. Available since Lodash 4.0.0. ```javascript _.sampleSize([1, 2, 3], 2); // => [3, 1] _.sampleSize([1, 2, 3], 4); // => [2, 3, 1] ``` -------------------------------- ### Generate Source Map Source: https://lodash.com/custom-builds Create a source map for the build output, which can be used for debugging. An optional source map URL can be specified. Use the `-m` or `--source-map` flag. ```bash -m ``` -------------------------------- ### _.nth Source: https://lodash.com/docs Gets the element at index n of an array. ```APIDOC ## _.nth(array, [n=0]) ### Description Gets the element at index n of array. If n is negative, the nth element from the end is returned. ### Parameters - **array** (Array) - Required - The array to query. - **[n=0]** (number) - Optional - The index of the element to return. ### Response - **Returns** (*) - Returns the nth element of array. ``` -------------------------------- ### Build with Specific Categories Source: https://lodash.com/custom-builds Create a custom build by specifying comma-separated categories of functions to include. Valid categories include array, collection, date, function, lang, object, number, seq, string, and util. ```bash lodash category=collection,function ``` -------------------------------- ### _.setWith(object, path, value, [customizer]) Source: https://lodash.com/docs This method is like `_.set` except that it accepts `customizer` which is invoked to produce the objects of path. If `customizer` returns `undefined` path creation is handled by the method instead. The `customizer` is invoked with three arguments: (nsValue, key, nsObject). Note: This method mutates object. ```APIDOC ## _.setWith(object, path, value, [customizer]) ### Description This method is like `_.set` except that it accepts `customizer` which is invoked to produce the objects of path. If `customizer` returns `undefined` path creation is handled by the method instead. The `customizer` is invoked with three arguments: (nsValue, key, nsObject). Note: This method mutates object. ### Method POST ### Endpoint /websites/lodash ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **object** (Object) - Required - The object to modify. - **path** (Array|string) - Required - The path of the property to set. - **value** (*) - Required - The value to set. - **[customizer]** (Function) - Optional - The function to customize assigned values. ### Request Example ```json { "object": {}, "path": "[0][1]", "value": "a", "customizer": "Object" } ``` ### Response #### Success Response (200) - **Object** - Returns object. #### Response Example ```json { "0": { "1": "a" } } ``` ``` -------------------------------- ### _.lastIndexOf Source: https://lodash.com/docs Gets the index of the last occurrence of a value in an array. ```APIDOC ## _.lastIndexOf(array, value, [fromIndex=array.length-1]) ### Description This method is like _.indexOf except that it iterates over elements of array from right to left. ### Parameters - **array** (Array) - Required - The array to inspect. - **value** (*) - Required - The value to search for. - **[fromIndex=array.length-1]** (number) - Optional - The index to search from. ### Response - **Returns** (number) - Returns the index of the matched value, else -1. ``` -------------------------------- ### _.indexOf Source: https://lodash.com/docs Gets the index at which the first occurrence of a value is found. ```APIDOC ## _.indexOf(array, value, [fromIndex=0]) ### Description Gets the index at which the first occurrence of value is found in array using SameValueZero for equality comparisons. ### Parameters #### Arguments - **array** (Array) - Required - The array to inspect. - **value** (*) - Required - The value to search for. - **fromIndex** (number) - Optional - The index to search from. ### Returns - **index** (number) - Returns the index of the matched value, else -1. ``` -------------------------------- ### Create a Core Build Source: https://lodash.com/custom-builds Generate a core build of Lodash, which is a minimal build approximately 4kB in size. Use the `core` modifier to create this build. ```bash lodash core ``` -------------------------------- ### _.pick Source: https://lodash.com/docs Creates an object composed of the picked object properties. ```APIDOC ## _.pick(object, [paths]) ### Description Creates an object composed of the picked `object` properties. ### Parameters - **object** (Object) - Required - The source object. - **paths** (...(string|string[])) - Optional - The property paths to pick. ### Response - **Returns** (Object) - Returns the new object. ### Example ```javascript var object = { 'a': 1, 'b': '2', 'c': 3 }; _.pick(object, ['a', 'c']); // => { 'a': 1, 'c': 3 } ``` ``` -------------------------------- ### Get first element Source: https://lodash.com/docs Retrieves the first element of an array. ```javascript _.head([1, 2, 3]); // => 1   _.head([]); // => undefined ``` -------------------------------- ### Array Methods - _.compact Source: https://lodash.com/docs Creates an array with all falsey values removed. The values `false`, `null`, `0`, `-0`, `0n`, `""`, `undefined`, and `NaN` are falsy. ```APIDOC ## _.compact(array) ### Description Creates an array with all falsey values removed. The values `false`, `null`, `0`, `-0`, `0n`, `""`, `undefined`, and `NaN` are falsy. ### Method GET ### Endpoint /websites/lodash ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript _.compact([0, 1, false, 2, '', 3]); // => [1, 2, 3] ``` ### Response #### Success Response (200) - **result** (Array) - Returns the new array of filtered values. #### Response Example ```json { "result": [ 1, 2, 3 ] } ``` ``` -------------------------------- ### _.isMatchWith(object, source, [customizer]) Source: https://lodash.com/docs This method is like `_.isMatch` except that it accepts `customizer` which is invoked to compare values. If `customizer` returns `undefined`, comparisons are handled by the method instead. The `customizer` is invoked with five arguments: _(objValue, srcValue, index|key, object, source)_. ```APIDOC ## _.isMatchWith(object, source, [customizer]) ### Description This method is like `_.isMatch` except that it accepts `customizer` which is invoked to compare values. If `customizer` returns `undefined`, comparisons are handled by the method instead. The `customizer` is invoked with five arguments: _(objValue, srcValue, index|key, object, source)_. ### Method Utility ### Arguments 1. `object` (Object): The object to inspect. 2. `source` (Object): The object of property values to match. 3. `[customizer]` (Function): The function to customize comparisons. ### Returns (boolean): Returns `true` if `object` is a match, else `false`. ### Example ```javascript function isGreeting(value) { return /^h(?:i|ello)$/.test(value); } function customizer(objValue, srcValue) { if (isGreeting(objValue) && isGreeting(srcValue)) { return true; } } var object = { 'greeting': 'hello' }; var source = { 'greeting': 'hi' }; _.isMatchWith(object, source, customizer); // => true ``` ``` -------------------------------- ### _.now() Source: https://lodash.com/docs Gets the timestamp of the number of milliseconds that have elapsed since the Unix epoch. ```APIDOC ## _.now() ### Description Gets the timestamp of the number of milliseconds that have elapsed since the Unix epoch _(1 January`1970 00` :00:00 UTC)_. ### Returns _(number)_ : Returns the timestamp. ### Example ```javascript _.defer(function(stamp) { console.log(_.now() - stamp); }, _.now()); // => Logs the number of milliseconds it took for the deferred invocation. ``` ``` -------------------------------- ### Get tail of array Source: https://lodash.com/docs Returns all elements of an array except the first one. ```javascript _.tail([1, 2, 3]); // => [2, 3] ``` -------------------------------- ### Generate Production Output Source: https://lodash.com/custom-builds Create a minified production version of the Lodash build. Use the `-p` or `--production` flag. ```bash -p ``` -------------------------------- ### Get all but last element Source: https://lodash.com/docs Returns all elements of an array except the last one. ```javascript _.initial([1, 2, 3]); // => [1, 2] ``` -------------------------------- ### Get unique values from sorted array Source: https://lodash.com/docs Optimized duplicate removal for sorted arrays. ```javascript _.sortedUniq([1, 1, 2]); // => [1, 2] ``` -------------------------------- ### Trim strings Source: https://lodash.com/docs Remove whitespace or specific characters from the start, end, or both sides of a string. ```javascript _.trim(' abc '); // => 'abc' _.trim('-_-abc-_-', '_-'); // => 'abc' _.map([' foo ', ' bar '], _.trim); // => ['foo', 'bar'] ``` ```javascript _.trimEnd(' abc '); // => ' abc' _.trimEnd('-_-abc-_-', '_-'); // => '-_-abc' ``` ```javascript _.trimStart(' abc '); // => 'abc ' _.trimStart('-_-abc-_-', '_-'); // => 'abc-_-' ``` -------------------------------- ### Clone with customizer using _.cloneWith Source: https://lodash.com/docs Performs a shallow clone using a customizer function to handle specific types. ```javascript function customizer(value) {   if (_.isElement(value)) {     return value.cloneNode(false);   } }   var el = _.cloneWith(document.body, customizer);   console.log(el === document.body); // => false console.log(el.nodeName); // => 'BODY' console.log(el.childNodes.length); // => 0 ``` -------------------------------- ### Lodash capitalize Example Source: https://lodash.com/docs Converts the first character of a string to uppercase and the rest to lowercase. ```javascript _.capitalize('FRED'); // => 'Fred' ``` -------------------------------- ### _.noop() Source: https://lodash.com/docs This method returns `undefined`. ```APIDOC ## _.noop() ### Description This method returns `undefined`. ### Returns _(*)_ : Returns `undefined`. ### Example ```javascript var func = _.noop; func(); // => undefined ``` ``` -------------------------------- ### Generate Development Output Source: https://lodash.com/custom-builds Create a non-minified development version of the Lodash build. Use the `-d` or `--development` flag. ```bash -d ``` -------------------------------- ### _.rangeRight([start=0], end, [step=1]) Source: https://lodash.com/docs This method is like _.range except that it populates values in descending order. ```APIDOC ## _.rangeRight([start=0], end, [step=1]) ### Description This method is like `_.range` except that it populates values in descending order. ### Method Function ### Endpoint N/A (Utility Function) ### Parameters #### Arguments - **[start=0]** (number) - Optional - The start of the range. - **end** (number) - Required - The end of the range. - **[step=1]** (number) - Optional - The value to increment or decrement by. ### Returns - **Array** - Returns the range of numbers. ### Example ```javascript _.rangeRight(4); // => [3, 2, 1, 0] _.rangeRight(-4); // => [-3, -2, -1, 0] _.rangeRight(1, 5); // => [4, 3, 2, 1] _.rangeRight(0, 20, 5); // => [15, 10, 5, 0] _.rangeRight(0, -4, -1); // => [-3, -4] ``` ``` -------------------------------- ### Get own enumerable keys with _.keys Source: https://lodash.com/docs Returns an array of an object's own enumerable property names. ```javascript function Foo() {   this.a = 1;   this.b = 2; }   Foo.prototype.c = 3;   _.keys(new Foo); // => ['a', 'b'] (iteration order is not guaranteed)   _.keys('hi'); // => ['0', '1'] ``` -------------------------------- ### Pick Properties with _.pick Source: https://lodash.com/docs Creates a new object composed of the specified picked properties. ```javascript var object = { 'a': 1, 'b': '2', 'c': 3 }; _.pick(object, ['a', 'c']); // => { 'a': 1, 'c': 3 } ``` -------------------------------- ### _.at Source: https://lodash.com/docs Creates an array of values corresponding to paths of an object. ```APIDOC ## _.at(object, [paths]) ### Description Creates an array of values corresponding to paths of object. ### Parameters #### Arguments - **object** (Object) - Required - The object to iterate over. - **paths** (...(string|string[])) - Optional - The property paths to pick. ### Response - **Returns** (Array) - Returns the picked values. ``` -------------------------------- ### Return empty strings with _.stubString Source: https://lodash.com/docs Returns an empty string. ```javascript _.times(2, _.stubString); // => ['', ''] ``` -------------------------------- ### Number Method: _.inRange Source: https://lodash.com/docs Checks if a number is within a specified range (start inclusive, end exclusive). ```APIDOC ## _.inRange(number, [start=0], end) ### Description Checks if `n` is between `start` and up to, but not including, `end`. If `end` is not specified, it's set to `start` with `start` then set to `0`. If `start` is greater than `end` the params are swapped to support negative ranges. ### Arguments 1. `number` _(number)_ : The number to check. 2. `[start=0]` _(number)_ : The start of the range. 3. `end` _(number)_ : The end of the range. ### Returns _(boolean)_ : Returns `true` if `number` is in the range, else `false`. ### Example ```javascript _.inRange(3, 2, 4); // => true _.inRange(4, 8); // => true _.inRange(4, 2); // => false _.inRange(2, 2); // => false _.inRange(1.2, 2); // => true _.inRange(5.2, 4); // => false _.inRange(-3, -2, -6); // => true ``` ``` -------------------------------- ### Lodash Value Example Source: https://lodash.com/docs Shows how to resolve the unwrapped value of a chain sequence using the `value` method. ```javascript _([1, 2, 3]).value(); // => [1, 2, 3] ``` -------------------------------- ### Creating Objects with Prototypes using create Source: https://lodash.com/docs Use `_.create` to instantiate an object that inherits from a specified prototype. Optionally, assign properties to the newly created object. ```javascript function Shape() { this.x = 0; this.y = 0; } function Circle() { Shape.call(this); } Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle }); var circle = new Circle; circle instanceof Circle; // => true circle instanceof Shape; // => true ``` -------------------------------- ### Map Keys with _.mapKeys Source: https://lodash.com/docs Creates an object with keys generated by running each property through an iteratee. ```javascript _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) { return key + value; }); // => { 'a1': 1, 'b2': 2 } ``` -------------------------------- ### Get Function Property Names (Own) - Lodash Source: https://lodash.com/docs Creates an array containing the names of own enumerable function properties of an object. ```javascript function Foo() {   this.a = _.constant('a');   this.b = _.constant('b'); } Foo.prototype.c = _.constant('c'); _.functions(new Foo); // => ['a', 'b'] ``` -------------------------------- ### _.create Source: https://lodash.com/docs Creates an object that inherits from the prototype object. ```APIDOC ## _.create(prototype, [properties]) ### Description Creates an object that inherits from the prototype object. If a properties object is given, its own enumerable string keyed properties are assigned to the created object. ### Parameters #### Arguments - **prototype** (Object) - Required - The object to inherit from. - **properties** (Object) - Optional - The properties to assign to the object. ### Response - **Returns** (Object) - Returns the new object. ``` -------------------------------- ### Get unique values from sorted array by iteratee Source: https://lodash.com/docs Removes duplicates from a sorted array based on an iteratee function. ```javascript _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor); // => [1.1, 2.3] ``` -------------------------------- ### _.keysIn(object) Source: https://lodash.com/docs Creates an array of the own and inherited enumerable property names of `object`. Non-object values are coerced to objects. ```APIDOC ## GET _.keysIn(object) ### Description Creates an array of the own and inherited enumerable property names of `object`. Non-object values are coerced to objects. ### Method GET ### Endpoint /lodash/keysIn ### Parameters #### Path Parameters - **object** (Object) - Required - The object to query. ### Request Example ```json { "object": { "a": 1, "b": 2 } } ``` ### Response #### Success Response (200) - **keys** (Array) - Returns the array of property names. #### Response Example ```json { "keys": ["a", "b", "c"] } ``` ``` -------------------------------- ### Lodash endsWith Example Source: https://lodash.com/docs Checks if a string ends with a specified target string, optionally within a given position. ```javascript _.endsWith('abc', 'c'); // => true _.endsWith('abc', 'b'); // => false _.endsWith('abc', 'b', 2); // => true ``` -------------------------------- ### Configure Template Settings Source: https://lodash.com/custom-builds Pass specific template settings to be used during the precompilation of templates. This allows customization of interpolation, escape, and other template behaviors. ```bash lodash settings="{interpolate:/\{\{([sS]+?)\}\/g}" ``` -------------------------------- ### Lodash camelCase Example Source: https://lodash.com/docs Converts a string to camel case. Handles various separators like hyphens and underscores. ```javascript _.camelCase('Foo Bar'); // => 'fooBar' _.camelCase('--foo-bar--'); // => 'fooBar' _.camelCase('__FOO_BAR__'); // => 'fooBar' ```