eslint-plugin-you-dont-need-lodash-underscore
Lodash and Underscore are great modern JavaScript utility libraries, and they are widely used by Front-end developers. However, when you are targeting modern browsers, you may find out that there are many methods which are already supported natively thanks to ECMAScript5 [ES5] and ECMAScript2015 [ES6]. If you want your project to require fewer dependencies, and you know your target browser clearly, then you may not need Lodash/Underscore.
You are welcome to contribute with more items provided below.
**If you are targeting legacy JavaScript engine with those ES5 methods, you can use es5-shim
**Please note that, the examples used below are just showing you the native alternative of performing certain tasks. For some of the functions, Lodash provides you more options than native built-ins. This list is not a 1:1 comparison.
Voice of Developers
Make use of native JavaScript object and array utilities before going big.
—Cody Lindley, Author of jQuery Cookbook and JavaScript Enlightenment
You probably don't need Lodash. Nice List of JavaScript methods which you can use natively.
—Daniel Lamb, Computer Scientist, Technical Reviewer of Secrets of the JavaScript Ninja and Functional Programming in JavaScript
—Tero Parviainen, Author of build-your-own-angular
I'll admit, I've been guilty of overusing #lodash. Excellent resource.
—@therebelrobot, Maker of web things, Facilitator for Node.js/io.js
ESLint Plugin
If you're using ESLint, you can install a plugin that will help you identify places in your codebase where you don't (may not) need Lodash/Underscore.
Install the plugin...
npm install --save-dev eslint-plugin-you-dont-need-lodash-underscore
...then update your config
"extends" : "plugin:you-dont-need-lodash-underscore/compatible"
For more information, see Configuring the ESLint Plugin
Quick Links
- _.compact
- _.concat
- _.fill
- _.find
- _.findIndex
- _.first
- _.flatten
- _.flattenDeep
- _.fromPairs
- _.head and _.tail
- _.indexOf
- _.join
- _.last
- _.lastIndexOf
- _.reverse
- _.without
- _.slice
- _.isArray
❗️Important: Note that the native equivalents are array methods, and will not work with objects. If this functionality is needed, then Lodash/Underscore is the better option.
- _.each
- _.every
- _.filter
- _.groupBy
- _.includes
- _.map
- _.minBy and _.maxBy
- _.pluck
- _.range
- _.reduce
- _.reduceRight
- _.size
- _.some
- _.uniq
Array
_.compact
Creates an array with all falsy values removed.
// Underscore/Lodash_compact0 1 false 2 '' 3; // Native0 1 false 2 '' 3
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 1.5 ✔ | 9 ✔ | ✔ | ✔ |
_.concat
Creates a new array concatenating array with any additional arrays and/or values.
// Underscore/Lodashvar array = 1var other = _ console// output: [1, 2, 3, [4]] // Nativevar array = 1var other = array console// output: [1, 2, 3, [4]]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
1.0 ✔ | 1.0 ✔ | 5.5 ✔ | ✔ | ✔ |
_.fill
Fills elements of array with value from start up to, but not including, end.
Note that fill
is a mutable method in both native and Lodash/Underscore.
// Underscore/Lodashvar array = 1 2 3 _ console// output: ['a', 'a', 'a'] _// output: [2, 2, 2] _// output: [4, '*', '*', 10] // Nativevar array = 1 2 3 array console// output: ['a', 'a', 'a'] Array3// output: [2, 2, 2] 4 6 8 10// output: [4, '*', '*', 10]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
45.0 ✔ | 31.0 ✔ | Not supported | 32.0 ✔ | 7.1 ✔ |
_.find
Returns the value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned.
// Underscore/Lodashvar users = 'user': 'barney' 'age': 36 'active': true 'user': 'fred' 'age': 40 'active': false 'user': 'pebbles' 'age': 1 'active': true _// output: object for 'barney' // Nativevar users = 'user': 'barney' 'age': 36 'active': true 'user': 'fred' 'age': 40 'active': false 'user': 'pebbles' 'age': 1 'active': true users// output: object for 'barney'
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
45.0 ✔ | 25.0 ✔ | Not supported | 32.0 ✔ | 7.1 ✔ |
_.findIndex
Returns the index of the first element in the array that satisfies the provided testing function. Otherwise -1 is returned.
// Underscore/Lodashvar users = 'user': 'barney' 'age': 36 'active': true 'user': 'fred' 'age': 40 'active': false 'user': 'pebbles' 'age': 1 'active': true var index = _console// output: 1 // Nativevar users = 'user': 'barney' 'age': 36 'active': true 'user': 'fred' 'age': 40 'active': false 'user': 'pebbles' 'age': 1 'active': true var index = usersconsole// output: 1
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
45.0 ✔ | 25.0 ✔ | Not supported | 32.0 ✔ | 7.1 ✔ |
_.first
Returns the first element of an array. Passing n will return the first n elements of the array.
// Underscore/Lodash_;// => 1 _;// => [1, 2] // Native1 2 3 4 50;// => 1 1 2 3 4 5;// => [1, 2]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | ✔ | ✔ | ✔ | ✔ |
_.flatten
Flattens array a single level deep.
// Underscore/Lodash_;// => [1, 2, [3, [4]], 5] // Nativeconst flatten = 1 2 3 4 5// => [1, 2, [3, [4]], 5]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
46.0 ✔ | 3.0 ✔ | 9.0 ✔ | 10.5 ✔ | 7.1 ✔ |
_.flattenDeep
Recursively flattens array.
// Underscore/Lodash_;// => [1, 2, 3, 4, 5] // Nativeconst flattenDeep = Array ? arr : arr // => [1, 2, 3, 4, 5]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
46.0 ✔ | 16.0 ✔ | Not supported | 37.0 ✔ | 7.1 ✔ |
_.fromPairs
Returns an object composed from key-value pairs.
// Underscore/Lodash_;// => { 'a': 1, 'b': 2 } // Nativeconst fromPairs = { return arr} // Compact formconst fromPairs = arr ;// => { 'a': 1, 'b': 2 }
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 3.0 ✔ | 9 ✔ | 10.5 ✔ | 4.0 ✔ |
_.head and _.tail
Gets the first element or all but the first element.
const array = 1 2 3 // Underscore: _.first, _.head, _.take// Lodash: _.first, _.head_// output: 1 // Underscore: _.rest, _.tail, _.drop// Lodash: _.tail_// output: [2, 3] // Nativeconst head ...tail = arrayconsole// output: 1console// output [2, 3]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
49 ✔ | 34 ✔ | Not Supported | 37 ✔ | ✔ |
_.indexOf
Returns the first index at which a given element can be found in the array, or -1 if it is not present.
// Underscore/Lodashvar array = 2 9 9var result = _console// output: 0 // Nativevar array = 2 9 9var result = arrayconsole// output: 0
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 1.5 ✔ | 9 ✔ | ✔ | ✔ |
_.join
❗️Lodash only
Joins a list of elements in an array with a given separator.
// Lodashvar result = _console// output: 'one--two--three' // Nativevar result = 'one' 'two' 'three'console// output: 'one--two--three'
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
1.0 ✔ | 1.0 ✔ | 5.5 ✔ | ✔ | ✔ |
_.last
Returns the last element of an array. Passing n will return the last n elements of the array.
// Underscore/Lodashconst numbers = 1 2 3 4 5;_;// => 5 _;// => [4, 5] // Nativeconst numbers = 1 2 3 4 5;numbersnumberslength - 1;// => 5//ornumbers0;// => 5 numbers;// => [4, 5]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | ✔ | ✔ | ✔ | ✔ |
_.lastIndexOf
Returns the index of the last occurrence of value in the array, or -1 if value is not present.
// Underscore/Lodashvar array = 2 9 9 4 3 6var result = _console// output: 2 // Nativevar array = 2 9 9 4 3 6var result = arrayconsole// output: 2
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | ✔ | 9 ✔ | ✔ | ✔ |
_.reverse
❗️Lodash only
Reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
// Lodashvar array = 1 2 3console// output: [3, 2, 1] // Nativevar array = 1 2 3console// output: [3, 2, 1]
Voice from the Lodash author:
Lodash's
_.reverse
just callsArray#reverse
and enables composition like_.map(arrays, _.reverse).
It's exposed on _ because previously, likeUnderscore
, it was only exposed in the chaining syntax. --- jdalton
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
1.0 ✔ | 1.0 ✔ | 5.5 ✔ | ✔ | ✔ |
_.without
❗️Lodash only
Returns an array where matching items are filtered.
// Lodashvar array = 1 2 3console// output: [1, 3] // Nativevar array = 1 2 3console;// output: [1, 3]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
1.0 ✔ | 1.5 ✔ | 9 ✔ | ✔ | ✔ |
_.slice
Returns a shallow copy of a portion of an array into a new array object selected from begin
to end
(end
not included)
// Lodashvar array = 1 2 3 4console// output: [2, 3] // Nativevar array = 1 2 3 4console;// output: [2, 3]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | ✔ | ✔ | ✔ | ✔ |
_.isArray
Returns true if given value is an array.
// Lodashvar array = console// output: true // Nativevar array = console;// output: true
#### Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
5 ✔ | 4 ✔ | 9 ✔ | 10.5 ✔ | 5 ✔ |
Collection*
❗️Important: Note that the native equivalents are array methods, and will not work with objects. If this functionality is needed, then Lodash/Underscore is the better option.
_.each
Iterates over a list of elements, yielding each in turn to an iteratee function.
// Underscore/Lodash_// output: 1 2 3 // Native1 2 3// output: 1 2 3
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 1.5 ✔ | 9 ✔ | ✔ | ✔ |
_.every
Tests whether all elements in the array pass the test implemented by the provided function.
// Underscore/Lodash { return element >= 10}var array = 10 20 30var result = _console// output: true // Native { return element >= 10} var array = 10 20 30var result = arrayconsole// output: true
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 1.5 ✔ | 9 ✔ | ✔ | ✔ |
_.filter
Creates a new array with all elements that pass the test implemented by the provided function.
// Underscore/Lodash { return value >= 10}var array = 12 5 8 130 44var filtered = _console// output: [12, 130, 44] // Native { return value >= 10}var array = 12 5 8 130 44var filtered = arrayconsole// output: [12, 130, 44]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 1.5 ✔ | 9 ✔ | ✔ | ✔ |
_.groupBy
Group items by key.
// Underscore/Lodashvar grouped = _console// output: {3: ["one", "two"], 5: ["three"]} // Nativevar grouped = 'one' 'two' 'three'console// output: {3: ["one", "two"], 5: ["three"]}
// Underscore/Lodashvar grouped = _console// output: {1: [1.3], 2: [2.1, 2.4]} // Nativevar grouped = 13 21 24console// output: {1: [1.3], 2: [2.1, 2.4]}
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 3.0 ✔ | 9 ✔ | 10.5 ✔ | 4.0 ✔ |
_.includes
Checks if a value is in collection.
var array = 1 2 3// Underscore/Lodash - also called _.contains_// output: true // Nativevar array = 1 2 3array// output: true // Native (does not use same value zero)var array = 1 2 3array > -1// output: true
Array.prototype.includes
Browser Support for ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
47 ✔ | 43 ✔ | Not supported | 34 ✔ | 9 ✔ |
Array.prototype.indexOf
Browser Support for ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | ✔ | ✔ | ✔ | ✔ |
_.map
Translates all items in an array or object to new array of items.
// Underscore/Lodashvar array1 = 1 2 3var array2 = _console// output: [2, 4, 6] // Nativevar array1 = 1 2 3var array2 = array1console// output: [2, 4, 6]
_.minBy and _.maxBy
Use Array#reduce for find the maximum or minimum collection item
// Underscore/Lodashvar data = value: 6 value: 2 value: 4 var minItem = _var maxItem = _console// output: { value: 2 } { value: 6 } // Nativevar data = value: 6 value: 2 value: 4 var minItem = datavar maxItem = dataconsole// output: { value: 2 }, { value: 6 }
Extract a functor and use es2015 for better code
// utilsconst makeSelect = ? a : bconst minByValue = const maxByValue = // main logicconst data = value: 6 value: 2 value: 4 const minItem = dataconst maxItem = data console// output: { value: 2 }, { value: 6 } // or also more universal and little slower variant of minByconst minBy = { // slower because need to create a lambda function for each call... const select = akey <= bkey ? a : b return collection} console// output: { value: 2 }
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 3.0 ✔ | 9 ✔ | 10.5 ✔ | 4.0 ✔ |
_.pluck
array.map
or _.map
can also be used to replace _.pluck
. Lodash v4.0 removed _.pluck
in favor of _.map
with iteratee shorthand. Details can be found in Changelog
// Underscore/Lodashvar array1 = name: "Alice" name: "Bob" name: "Jeremy"var names = _console// output: ["Alice", "Bob", "Jeremy"] // Nativevar array1 = name: "Alice" name: "Bob" name: "Jeremy"var names = array1console// output: ["Alice", "Bob", "Jeremy"]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 1.5 ✔ | 9 ✔ | ✔ | ✔ |
_.reduce
Applies a function against an accumulator and each value of the array (from left-to-right) to reduce it to a single value.
// Underscore/Lodashvar array = 0 1 2 3 4var result = _console// output: 10 // Nativevar array = 0 1 2 3 4var result = arrayconsole// output: 10
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 3.0 ✔ | 9 ✔ | 10.5 ✔ | 4.0 ✔ |
_.range
Creates an array of numbers progressing from start up to.
// Underscore/Lodash_ // output: [0, 1, 2, 3]_ // output: [0, -1, -2, -3]_ // output: [1, 2, 3, 4]_ // output: [0, 5, 10, 15] // Native ( solution with Array.from )Array // output: [0, 1, 2, 3]Array // output: [0, -1, -2, -3]Array // output: [1, 2, 3, 4]Array // output: [0, 5, 10, 15] // Native ( solution with keys() and spread )...Array4 // output: [0, 1, 2, 3]
Browser Support ( Array.from )
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
45 ✔ | 32 ✔ | Not supported | ✔ | 9.0 ✔ |
Browser Support ( keys and array spread )
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
46 ✔ | 16 ✔ | Not supported | 37 ✔ | 7.1 ✔ |
_.reduceRight
This method is like _.reduce except that it iterates over elements of collection from right to left.
// Underscore/Lodashvar array = 0 1 2 3 4var result = _console// output: -2 // Nativevar array = 0 1 2 3 4var result = arrayconsole// output: -2
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 3.0 ✔ | 9 ✔ | 10.5 ✔ | 4.0 ✔ |
_.size
Returns the number of values in the collection.
// Underscore/Lodashvar result = _sizeone: 1 two: 2 three: 3console// output: 3 // Nativevar result2 = Objectlengthconsole// output: 3
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
5 ✔ | 4.0 ✔ | 9 ✔ | 12 ✔ | 5 ✔ |
_.some
Tests whether any of the elements in the array pass the test implemented by the provided function.
// Underscore/Lodash { return element >= 10}var array = 10 9 8var result = _console// output: true // Native { return element >= 10} var array = 10 9 8var result = arrayconsole// output: true
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
38 ✔ | 13 ✔ | Not Supported | 25 ✔ | 9 ✔ |
_.uniq
Produces a duplicate-free version of the array, using === to test object equality.
// Underscore/Lodashvar array = 1 2 1 4 1 3var result = _console// output: [1, 2, 4, 3] // Nativevar array = 1 2 1 4 1 3;var result = ...array;console// output: [1, 2, 4, 3]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | 1.5 ✔ | 9 ✔ | ✔ | ✔ |
Function
_.after
❗️Note this is an alternative implementation
Creates a version of the function that will only be run after first being called count times. Useful for grouping asynchronous responses, where you want to be sure that all the async calls have finished, before proceeding.
var notes = 'profile' 'settings'// Underscore/Lodashvar renderNotes = _notes // Nativenotes
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | ✔ | ✔ | ✔ | ✔ |
_.bind
Create a new function that calls func with thisArg and args.
var objA = x: 66 { return thisx + offset; } var objB = x: 67; // Underscore/Lodashvar boundOffsetX = _; // Nativevar boundOffsetX = objAoffsetX;
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | ✔ | 9 ✔ | ✔ | ✔ |
_.partial
Create a new function that calls func with args.
// Lodash { return greeting + ' ' + name;}var sayHelloTo = _; // Native { return greeting + ' ' + name;}var
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
62 ✔ | 56 ✔ | ✗ | 49 ✔ | 11 ✔ |
Lang
_.isNaN
Checks if a value is NaN.
// Underscore/Lodashconsole// output: true // Nativeconsole// output: true // ES6console// output: true
MDN:
In comparison to the global
isNaN()
function,Number.isNaN()
doesn't suffer the problem of forcefully converting the parameter to a number. This means it is now safe to pass values that would normally convert toNaN
, but aren't actually the same value asNaN
. This also means that only values of the type number, that are alsoNaN
, return true. Number.isNaN()
Voice from the Lodash author:
Lodash's
_.isNaN
is equiv to ES6Number.isNaN
which is different than the globalisNaN
. --- jdalton
isNaN
Browser Support for ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | ✔ | ✔ | ✔ | ✔ |
Number.isNaN
Browser Support for ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
25 ✔ | 15 ✔ | Not supported | ✔ | 9 ✔ |
Object
_.assign
The method is used to copy the values of all enumerable own properties from one or more source objects to a target object.
// Underscore: _.extendOwn// Lodash { thisc = 3;} { thise = 5;}Fooprototyped = 4;Barprototypef = 6;var result = _;console;// output: { 'c': 3, 'e': 5 } // Native { thisc = 3;} { thise = 5;}Fooprototyped = 4;Barprototypef = 6;var result = Object;console;// output: { 'c': 3, 'e': 5 }
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
45 ✔ | 34 ✔ | No support | 32 ✔ | 9 ✔ |
_.keys
Retrieves all the names of the object's own enumerable properties.
// Underscore/Lodashvar result = _console// output: ["one", "two", "three"] // Nativevar result2 = Objectconsole// output: ["one", "two", "three"]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
5 ✔ | 4.0 ✔ | 9 ✔ | 12 ✔ | 5 ✔ |
_.toPairs
Retrieves all the given object's own enumerable property [ key, value ]
pairs.
// Underscore - also called _.pairs// Lodash - also called _.entriesvar result = _console// output: [["one", 1], ["two", 2], ["three", 3]] // Nativevar result2 = Objectconsole// output: [["one", 1], ["two", 2], ["three", 3]]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
38 ✔ | 28 ✔ | Not supported | 25 ✔ | 7.1 ✔ |
_.values
Retrieves all the given object's own enumerable property values.
// Underscore/Lodashvar result = _console// output: [1, 2, 3] // Nativevar result2 = Objectconsole// output: [1, 2, 3]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
54 ✔ | 47 ✔ | Not supported | 41.0 ✔ | 10.1 ✔ |
String
_.repeat
❗️Lodash only
Repeats the given string n times.
// Lodashvar result = _// output: 'abcabc' // Nativevar result = 'abc'console// output: 'abcabc'
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
41 ✔ | 24 ✔ | Not supported | 28 ✔ | 9 ✔ |
_.template
❗️ Note this is an alternative implementation. Native template literals not escape html.
Create a template function.
// Lodash/Underscoreconst compiled = _;; // Nativeconst templateLitreal = `hello `;;
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
41 ✔ | 34 ✔ | Not supported | 28 ✔ | 9 ✔ |
_.toLower
❗️Lodash only
Lowercases a given string.
// Lodashvar result = _console// output: 'foobar' // Nativevar result = 'FOOBAR'console// output: 'foobar'
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | ✔ | ✔ | ✔ | ✔ |
_.toUpper
❗️Lodash only
Uppercases a given string.
// Lodashvar result = _console// output: 'FOOBAR' // Nativevar result = 'foobar'console// output: 'FOOBAR'
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | ✔ | ✔ | ✔ | ✔ |
_.trim
❗️Lodash only
Removes the leading and trailing whitespace characters from a string.
// Lodashvar result = _console// output: 'abc' // Nativevar result = ' abc 'console// output: 'abc'
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
5.0 ✔ | 3.5 ✔ | 9.0 ✔ | 10.5 ✔ | 5.0 ✔ |
_.replace
returns a new string with some or all matches of a pattern
replaced by a replacement
// Lodashvar re = /apples/gi;var str = 'Apples are round, and apples are juicy.';var newstr = _;console;// output: 'oranges are round, and oranges are juicy.' // Nativevar re = /apples/gi;var str = 'Apples are round, and apples are juicy.';var result = str;console;// output: 'oranges are round, and oranges are juicy.'
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
✔ | ✔ | ✔ | ✔ | ✔ |
Reference
_.uniq
Removes all duplicates entries from an array.
// Underscore/Lodashvar result = _;console// output: [1, 2, 4, 3] // Nativevar result = ... 1 2 1 4 1 3console// output: [1, 2, 4, 3]
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
38 ✔ | 13 ✔ | 11 ✔ | 25 ✔ | 7.1 ✔ |
Inspired by:
License
MIT