Shared Flashcard Set

Details

Lodash
Lodash terms
315
Computer Science
Professional
04/13/2021

Additional Computer Science Flashcards

 


 

Cards

Term
VERSION
Definition
The semantic version number.
Term
_
Definition

function square(n) { return n * n; }

var wrapped = f([1, 2, 3]); // Returns an unwrapped value.

wrapped.reduce(_.add); // 6

// Returns a wrapped value.

var squares = wrapped.map(square);

_.isArray(squares); // false

_.isArray(squares.value()); // true

Term
add
Definition
_.f(6, 4); // 10
Term
after
Definition

var saves = ['profile', 'settings'];

var done = _.f(saves.length, () => { console.log('done saving!'); });

_.forEach(saves, type => { asyncSave({ 'type': type, 'complete': done });

}); // => Logs 'done saving!' after the two async saves have completed.

Term
ary
Definition
_.map(['6', '8', '10'], _.f(parseInt, 1)); // [6, 8, 10]
Term
assign
Definition

function Foo() { this.a = 1; }

function Bar() { this.c = 3; }

Foo.prototype.b = 2;

Bar.prototype.d = 4;

_.f({ 'a': 0 }, new Foo, new Bar); // { 'a': 1, 'c': 3 }

Term
assignIn
Definition

function Foo() { this.a = 1; }

function Bar() { this.c = 3; }

Foo.prototype.b = 2;

Bar.prototype.d = 4;

_.f({ 'a': 0 }, new Foo, new Bar); // { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }

Term
assignInWith
Definition

function customizer(objValue, srcValue) { return _.isUndefined(objValue) ? srcValue : objValue; }

var defaults = _.partialRight(_.f, customizer);

defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); // { 'a': 1, 'b': 2 }

Term
assignWith
Definition

function customizer(objValue, srcValue) { return _.isUndefined(objValue) ? srcValue : objValue; }

var defaults = _.partialRight(_.f, customizer);

defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); // { 'a': 1, 'b': 2 }

Term
at
Definition

var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };

_.f(object, ['a[0].b.c', 'a[1]']); // [3, 4]

Term
attempt
Definition

// Avoid throwing errors for invalid selectors.

var elements = _.f(function(selector) { return document.querySelectorAll(selector); }, '>_>');

if (_.isError(elements)) { elements = []; }

Term
before
Definition
jQuery(element).on('click', _.f(5, addContactToList)); // Allows adding up to 4 contacts to the list.
Term
bind
Definition

function greet(greeting, punctuation) { return greeting + ' ' + this.user + punctuation; }

var object = { 'user': 'fred' };

var bound = _.f(greet, object, 'hi'); bound('!'); // 'hi fred!' // Bound with placeholders.

var bound = _.f(greet, object, _, '!');

bound('hi'); // 'hi fred!'

Term
bindAll
Definition

var view = { 'label': 'docs', 'click': () => { console.log('clicked ' + this.label); } };

_.f(view, ['click']);

jQuery(element).on('click', view.click); // Logs 'clicked docs' when clicked.

Term
bindKey
Definition
var object = {
'user': 'fred',
'greet': function(greeting, punctuation) {
return greeting + ' ' + this.user + punctuation;
}
};

var bound = _.f(object, 'greet', 'hi');
bound('!');
// => 'hi fred!'

object.greet = function(greeting, punctuation) {
return greeting + 'ya ' + this.user + punctuation;
};

bound('!');
// => 'hiya fred!'

// Bound with placeholders.
var bound = _.f(object, 'greet', _, '!');
bound('hi');
// => 'hiya fred!'
Term
camelCase
Definition
_.f('Foo Bar');
// => 'fooBar'

_.f('--foo-bar--');
// => 'fooBar'

_.f('__FOO_BAR__');
// => 'fooBar'
Term
capitalize
Definition
_.f('FRED');
// => 'Fred'
Term
castArray
Definition
_.f(1);
// => [1]

_.f({ 'a': 1 });
// => [{ 'a': 1 }]

_.f('abc');
// => ['abc']

_.f(null);
// => [null]

_.f(undefined);
// => [undefined]

_.f();
// => []

var array = [1, 2, 3];
console.log(_.f(array) === array);
// => true
Term
ceil
Definition
_.f(4.006);
// => 5

_.f(6.004, 2);
// => 6.01

_.f(6040, -2);
// => 6100
Term
chain
Definition
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 },
{ 'user': 'pebbles', 'age': 1 }
];

var youngest = _
.f(users)
.sortBy('age')
.map(function(o) {
return o.user + ' is ' + o.age;
})
.head()
.value();
// => 'pebbles is 1'
Term
chunk
Definition
_.f(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]

_.f(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]
Term
clamp
Definition
_.f(-10, -5, 5);
// => -5

_.f(10, -5, 5);
// => 5
Term
clone
Definition
var objects = [{ 'a': 1 }, { 'b': 2 }];

var shallow = _.f(objects);
console.log(shallow[0] === objects[0]);
// => true
Term
cloneDeep
Definition
var objects = [{ 'a': 1 }, { 'b': 2 }];

var deep = _.f(objects);
console.log(deep[0] === objects[0]);
// => false
Term
cloneDeepWith
Definition
function customizer(value) {
if (_.isElement(value)) {
return value.cloneNode(true);
}
}

var el = _.f(document.body, customizer);

console.log(el === document.body);
// => false
console.log(el.nodeName);
// => 'BODY'
console.log(el.childNodes.length);
// => 20
Term
cloneWith
Definition
function customizer(value) {
if (_.isElement(value)) {
return value.cloneNode(false);
}
}

var el = _.f(document.body, customizer);

console.log(el === document.body);
// => false
console.log(el.nodeName);
// => 'BODY'
console.log(el.childNodes.length);
// => 0
Term
compact
Definition
_.f([0, 1, false, 2, '', 3]);
// => [1, 2, 3]
Term
concat
Definition
var array = [1];
var other = _.f(array, 2, [3], [[4]]);

console.log(other);
// => [1, 2, 3, [4]]

console.log(array);
// => [1]
Term
cond
Definition
var func = _.f([
[_.matches({ 'a': 1 }), _.constant('matches A')],
[_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
[_.stubTrue, _.constant('no match')]
]);

func({ 'a': 1, 'b': 2 });
// => 'matches A'

func({ 'a': 0, 'b': 1 });
// => 'matches B'

func({ 'a': '1', 'b': '2' });
// => 'no match'
Term
conforms
Definition
var objects = [
{ 'a': 2, 'b': 1 },
{ 'a': 1, 'b': 2 }
];

_.filter(objects, _.f({ 'b': function(n) { return n > 1; } }));
// => [{ 'a': 1, 'b': 2 }]
Term
conformsTo
Definition
var object = { 'a': 1, 'b': 2 };

_.f(object, { 'b': function(n) { return n > 1; } });
// => true

_.f(object, { 'b': function(n) { return n > 2; } });
// => false
Term
constant
Definition
var objects = _.times(2, _.f({ 'a': 1 }));

console.log(objects);
// => [{ 'a': 1 }, { 'a': 1 }]

console.log(objects[0] === objects[1]);
// => true
Term
countBy
Definition
_.f([6.1, 4.2, 6.3], Math.floor);
// => { '4': 1, '6': 2 }

// The `_.property` iteratee shorthand.
_.f(['one', 'two', 'three'], 'length');
// => { '3': 2, '5': 1 }
Term
create
Definition
function Shape() {
this.x = 0;
this.y = 0;
}

function Circle() {
Shape.call(this);
}

Circle.prototype = _.f(Shape.prototype, {
'constructor': Circle
});

var circle = new Circle;
circle instanceof Circle;
// => true

circle instanceof Shape;
// => true
Term
curry
Definition
var abc = function(a, b, c) {
return [a, b, c];
};

var curried = _.f(abc);

curried(1)(2)(3);
// => [1, 2, 3]

curried(1, 2)(3);
// => [1, 2, 3]

curried(1, 2, 3);
// => [1, 2, 3]

// Curried with placeholders.
curried(1)(_, 3)(2);
// => [1, 2, 3]
Term
curryRight
Definition
var abc = function(a, b, c) {
return [a, b, c];
};

var curried = _.f(abc);

curried(3)(2)(1);
// => [1, 2, 3]

curried(2, 3)(1);
// => [1, 2, 3]

curried(1, 2, 3);
// => [1, 2, 3]

// Curried with placeholders.
curried(3)(1, _)(2);
// => [1, 2, 3]
Term
debounce
Definition
// Avoid costly calculations while the window size is in flux.
jQuery(window).on('resize', _.f(calculateLayout, 150));

// Invoke `sendMail` when clicked, debouncing subsequent calls.
jQuery(element).on('click', _.f(sendMail, 300, {
'leading': true,
'trailing': false
}));

// Ensure `batchLog` is invoked once after 1 second of debounced calls.
var debounced = _.f(batchLog, 250, { 'maxWait': 1000 });
var source = new EventSource('/stream');
jQuery(source).on('message', debounced);

// Cancel the trailing debounced invocation.
jQuery(window).on('popstate', debounced.cancel);
Term
deburr
Definition
_.f('déjà vu');
// => 'deja vu'
Term
defaultTo
Definition
_.f(1, 10);
// => 1

_.f(undefined, 10);
// => 10
Term
defaults
Definition
_.f({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
// => { 'a': 1, 'b': 2 }
Term
defaultsDeep
Definition
_.f({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
// => { 'a': { 'b': 2, 'c': 3 } }
Term
defer
Definition
_.f(function(text) {
console.log(text);
}, 'deferred');
// => Logs 'deferred' after one millisecond.
Term
delay
Definition
_.f(function(text) {
console.log(text);
}, 1000, 'later');
// => Logs 'later' after one second.
Term
difference
Definition
_.f([2, 1], [2, 3]);
// => [1]
Term
differenceBy
Definition
_.f([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [1.2]

// The `_.property` iteratee shorthand.
_.f([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
// => [{ 'x': 2 }]
Term
differenceWith
Definition
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];

_.f(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
// => [{ 'x': 2, 'y': 1 }]
Term
divide
Definition
_.f(6, 4);
// => 1.5
Term
drop
Definition
_.f([1, 2, 3]);
// => [2, 3]

_.f([1, 2, 3], 2);
// => [3]

_.f([1, 2, 3], 5);
// => []

_.f([1, 2, 3], 0);
// => [1, 2, 3]
Term
dropRight
Definition
_.f([1, 2, 3]);
// => [1, 2]

_.f([1, 2, 3], 2);
// => [1]

_.f([1, 2, 3], 5);
// => []

_.f([1, 2, 3], 0);
// => [1, 2, 3]
Term
dropRightWhile
Definition
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': false }
];

_.f(users, function(o) { return !o.active; });
// => objects for ['barney']

// The `_.matches` iteratee shorthand.
_.f(users, { 'user': 'pebbles', 'active': false });
// => objects for ['barney', 'fred']

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => objects for ['barney']

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => objects for ['barney', 'fred', 'pebbles']
Term
dropWhile
Definition
var users = [
{ 'user': 'barney', 'active': false },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': true }
];

_.f(users, function(o) { return !o.active; });
// => objects for ['pebbles']

// The `_.matches` iteratee shorthand.
_.f(users, { 'user': 'barney', 'active': false });
// => objects for ['fred', 'pebbles']

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => objects for ['pebbles']

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => objects for ['barney', 'fred', 'pebbles']
Term
endsWith
Definition
_.f('abc', 'c');
// => true

_.f('abc', 'b');
// => false

_.f('abc', 'b', 2);
// => true
Term
eq
Definition
var object = { 'a': 1 };
var other = { 'a': 1 };

_.f(object, object);
// => true

_.f(object, other);
// => false

_.f('a', 'a');
// => true

_.f('a', Object('a'));
// => false

_.f(NaN, NaN);
// => true
Term
escape
Definition
_.f('fred, barney, & pebbles');
// => 'fred, barney, & pebbles'
Term
escapeRegExp
Definition
_.f('[lodash](https://lodash.com/)');
// => '\[lodash\]\(https://lodash\.com/\)'
Term
every
Definition
_.f([true, 1, null, 'yes'], Boolean);
// => false

var users = [
{ 'user': 'barney', 'age': 36, 'active': false },
{ 'user': 'fred', 'age': 40, 'active': false }
];

// The `_.matches` iteratee shorthand.
_.f(users, { 'user': 'barney', 'active': false });
// => false

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => true

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => false
Term
fill
Definition
var array = [1, 2, 3];

_.f(array, 'a');
console.log(array);
// => ['a', 'a', 'a']

_.f(Array(3), 2);
// => [2, 2, 2]

_.f([4, 6, 8, 10], '*', 1, 3);
// => [4, '*', '*', 10]
Term
filter
Definition
var users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false }
];

_.f(users, function(o) { return !o.active; });
// => objects for ['fred']

// The `_.matches` iteratee shorthand.
_.f(users, { 'age': 36, 'active': true });
// => objects for ['barney']

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => objects for ['fred']

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => objects for ['barney']
Term
find
Definition
var users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false },
{ 'user': 'pebbles', 'age': 1, 'active': true }
];

_.f(users, function(o) { return o.age < 40; });
// => object for 'barney'

// The `_.matches` iteratee shorthand.
_.f(users, { 'age': 1, 'active': true });
// => object for 'pebbles'

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => object for 'fred'

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => object for 'barney'
Term
findIndex
Definition
var users = [
{ 'user': 'barney', 'active': false },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': true }
];

_.f(users, function(o) { return o.user == 'barney'; });
// => 0

// The `_.matches` iteratee shorthand.
_.f(users, { 'user': 'fred', 'active': false });
// => 1

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => 0

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => 2
Term
findKey
Definition
var users = {
'barney': { 'age': 36, 'active': true },
'fred': { 'age': 40, 'active': false },
'pebbles': { 'age': 1, 'active': true }
};

_.f(users, function(o) { return o.age < 40; });
// => 'barney' (iteration order is not guaranteed)

// The `_.matches` iteratee shorthand.
_.f(users, { 'age': 1, 'active': true });
// => 'pebbles'

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => 'fred'

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => 'barney'
Term
findLast
Definition
_.f([1, 2, 3, 4], function(n) {
return n % 2 == 1;
});
// => 3
Term
findLastIndex
Definition
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': false }
];

_.f(users, function(o) { return o.user == 'pebbles'; });
// => 2

// The `_.matches` iteratee shorthand.
_.f(users, { 'user': 'barney', 'active': true });
// => 0

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => 2

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => 0
Term
findLastKey
Definition
var users = {
'barney': { 'age': 36, 'active': true },
'fred': { 'age': 40, 'active': false },
'pebbles': { 'age': 1, 'active': true }
};

_.findLastKey(users, function(o) { return o.age < 40; });
// => returns 'pebbles' assuming `_.f` returns 'barney'

// The `_.matches` iteratee shorthand.
_.f(users, { 'age': 36, 'active': true });
// => 'barney'

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => 'fred'

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => 'pebbles'
Term
flatMap
Definition
function duplicate(n) {
return [n, n];
}

_.f([1, 2], duplicate);
// => [1, 1, 2, 2]
Term
flatMapDeep
Definition
function duplicate(n) {
return [[[n, n]]];
}

_.f([1, 2], duplicate);
// => [1, 1, 2, 2]
Term
flatMapDepth
Definition
function duplicate(n) {
return [[[n, n]]];
}

_.f([1, 2], duplicate, 2);
// => [[1, 1], [2, 2]
Term
flatten
Definition
_.f([1, [2, [3, [4]], 5]]);
// => [1, 2, [3, [4]], 5]
Term
flattenDeep
Definition
_.f([1, [2, [3, [4]], 5]]);
// => [1, 2, 3, 4, 5]
Term
flattenDepth
Definition
var array = [1, [2, [3, [4]], 5]];

_.f(array, 1);
// => [1, 2, [3, [4]], 5]

_.f(array, 2);
// => [1, 2, 3, [4], 5]
Term
flip
Definition
var flipped = _.f(function() {
return _.toArray(arguments);
});

flipped('a', 'b', 'c', 'd');
// => ['d', 'c', 'b', 'a']
Term
floor
Definition
_.f(4.006);
// => 4

_.f(0.046, 2);
// => 0.04

_.f(4060, -2);
// => 4000
Term
flow
Definition
function square(n) {
return n * n;
}

var addSquare = _.f([_.add, square]);
addSquare(1, 2);
// => 9
Term
flowRight
Definition
function square(n) {
return n * n;
}

var addSquare = _.f([square, _.add]);
addSquare(1, 2);
// => 9
Term
forEach
Definition
_.f([1, 2], function(value) {
console.log(value);
});
// => Logs `1` then `2`.

_.f({ 'a': 1, 'b': 2 }, function(value, key) {
console.log(key);
});
// => Logs 'a' then 'b' (iteration order is not guaranteed).
Term
forEachRight
Definition
_.f([1, 2], function(value) {
console.log(value);
});
// => Logs `2` then `1`.
Term
forIn
Definition
function Foo() {
this.a = 1;
this.b = 2;
}

Foo.prototype.c = 3;

_.f(new Foo, function(value, key) {
console.log(key);
});
// => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
Term
forInRight
Definition
function Foo() {
this.a = 1;
this.b = 2;
}

Foo.prototype.c = 3;

_.f(new Foo, function(value, key) {
console.log(key);
});
// => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
Term
forOwn
Definition
function Foo() {
this.a = 1;
this.b = 2;
}

Foo.prototype.c = 3;

_.f(new Foo, function(value, key) {
console.log(key);
});
// => Logs 'a' then 'b' (iteration order is not guaranteed).
Term
forOwnRight
Definition
function Foo() {
this.a = 1;
this.b = 2;
}

Foo.prototype.c = 3;

_.f(new Foo, function(value, key) {
console.log(key);
});
// => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
Term
fromPairs
Definition
_.f([['a', 1], ['b', 2]]);
// => { 'a': 1, 'b': 2 }
Term
functions
Definition
function Foo() {
this.a = _.constant('a');
this.b = _.constant('b');
}

Foo.prototype.c = _.constant('c');

_.f(new Foo);
// => ['a', 'b']
Term
functionsIn
Definition
function Foo() {
this.a = _.constant('a');
this.b = _.constant('b');
}

Foo.prototype.c = _.constant('c');

_.f(new Foo);
// => ['a', 'b', 'c']
Term
get
Definition
var object = { 'a': [{ 'b': { 'c': 3 } }] };

_.f(object, 'a[0].b.c');
// => 3

_.f(object, ['a', '0', 'b', 'c']);
// => 3

_.f(object, 'a.b.c', 'default');
// => 'default'
Term
groupBy
Definition
_.f([6.1, 4.2, 6.3], Math.floor);
// => { '4': [4.2], '6': [6.1, 6.3] }

// The `_.property` iteratee shorthand.
_.f(['one', 'two', 'three'], 'length');
// => { '3': ['one', 'two'], '5': ['three'] }
Term
gt
Definition
_.f(3, 1);
// => true

_.f(3, 3);
// => false

_.f(1, 3);
// => false
Term
gte
Definition
_.f(3, 1);
// => true

_.f(3, 3);
// => true

_.f(1, 3);
// => false
Term
has
Definition
var object = { 'a': { 'b': 2 } };
var other = _.create({ 'a': _.create({ 'b': 2 }) });

_.f(object, 'a');
// => true

_.f(object, 'a.b');
// => true

_.f(object, ['a', 'b']);
// => true

_.f(other, 'a');
// => false
Term
hasIn
Definition
var object = _.create({ 'a': _.create({ 'b': 2 }) });

_.f(object, 'a');
// => true

_.f(object, 'a.b');
// => true

_.f(object, ['a', 'b']);
// => true

_.f(object, 'b');
// => false
Term
head
Definition
_.f([1, 2, 3]);
// => 1

_.head([]);
// => undefined
Term
identity
Definition
var object = { 'a': 1 };

console.log(_.f(object) === object);
// => true
Term
inRange
Definition
_.f(3, 2, 4);
// => true

_.f(4, 8);
// => true

_.f(4, 2);
// => false

_.f(2, 2);
// => false

_.f(1.2, 2);
// => true

_.f(5.2, 4);
// => false

_.f(-3, -2, -6);
// => true
Term
includes
Definition
_.f([1, 2, 3], 1);
// => true

_.f([1, 2, 3], 1, 2);
// => false

_.f({ 'a': 1, 'b': 2 }, 1);
// => true

_.f('abcd', 'bc');
// => true
Term
indexOf
Definition
_.f([1, 2, 1, 2], 2);
// => 1

// Search from the `fromIndex`.
_.f([1, 2, 1, 2], 2, 2);
// => 3
Term
initial
Definition
_.f([1, 2, 3]);
// => [1, 2]
Term
intersection
Definition
_.f([2, 1], [2, 3]);
// => [2]
Term
intersectionBy
Definition
_.f([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [2.1]

// The `_.property` iteratee shorthand.
_.f([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }]
Term
intersectionWith
Definition
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];

_.f(objects, others, _.isEqual);
// => [{ 'x': 1, 'y': 2 }]
Term
invert
Definition
var object = { 'a': 1, 'b': 2, 'c': 1 };

_.f(object);
// => { '1': 'c', '2': 'b' }
Term
invertBy
Definition
var object = { 'a': 1, 'b': 2, 'c': 1 };

_.f(object);
// => { '1': ['a', 'c'], '2': ['b'] }

_.f(object, function(value) {
return 'group' + value;
});
// => { 'group1': ['a', 'c'], 'group2': ['b'] }
Term
invoke
Definition
var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };

_.f(object, 'a[0].b.c.slice', 1, 3);
// => [2, 3]
Term
invokeMap
Definition
_.f([[5, 1, 7], [3, 2, 1]], 'sort');
// => [[1, 5, 7], [1, 2, 3]]

_.f([123, 456], String.prototype.split, '');
// => [['1', '2', '3'], ['4', '5', '6']]
Term
isArguments
Definition
_.f(function() { return arguments; }());
// => true

_.f([1, 2, 3]);
// => false
Term
isArray
Definition
_.f([1, 2, 3]);
// => true

_.f(document.body.children);
// => false

_.f('abc');
// => false

_.f(_.noop);
// => false
Term
isArrayBuffer
Definition
_.f(new ArrayBuffer(2));
// => true

_.f(new Array(2));
// => false
Term
isArrayLike
Definition
_.f([1, 2, 3]);
// => true

_.f(document.body.children);
// => true

_.f('abc');
// => true

_.f(_.noop);
// => false
Term
isArrayLikeObject
Definition
_.f([1, 2, 3]);
// => true

_.f(document.body.children);
// => true

_.f('abc');
// => false

_.f(_.noop);
// => false
Term
isBoolean
Definition
_.f(false);
// => true

_.f(null);
// => false
Term
isBuffer
Definition
_.f(new Buffer(2));
// => true

_.f(new Uint8Array(2));
// => false
Term
isDate
Definition
_.f(new Date); // => true _.f('Mon April 23 2012'); // => false
Term
isElement
Definition

_.f(document.body);

// => true

 

_.f("<body>");

// => false

Term
isEmpty
Definition
_.f(null);
// => true

_.f(true);
// => true

_.f(1);
// => true

_.f([1, 2, 3]);
// => false

_.f({ 'a': 1 });
// => false
Term
isEqual
Definition
var object = { 'a': 1 };
var other = { 'a': 1 };

_.f(object, other);
// => true

object === other;
// => false
Term
isEqualWith
Definition
function isGreeting(value) {
return /^h(?:i|ello)$/.test(value);
}

function customizer(objValue, othValue) {
if (isGreeting(objValue) && isGreeting(othValue)) {
return true;
}
}

var array = ['hello', 'goodbye'];
var other = ['hi', 'goodbye'];

_.f(array, other, customizer);
// => true
Term
isError
Definition
_.f(new Error);
// => true

_.f(Error);
// => false
Term
isFinite
Definition
_.f(3);
// => true

_.f(Number.MIN_VALUE);
// => true

_.f(Infinity);
// => false

_.f('3');
// => false
Term
isFunction
Definition
_.f(_);
// => true

_.f(/abc/);
// => false
Term
isInteger
Definition
_.f(3);
// => true

_.f(Number.MIN_VALUE);
// => false

_.f(Infinity);
// => false

_.f('3');
// => false
Term
isLength
Definition
_.f(3);
// => true

_.f(Number.MIN_VALUE);
// => false

_.f(Infinity);
// => false

_.f('3');
// => false
Term
isMap
Definition
_.f(new Map);
// => true

_.f(new WeakMap);
// => false
Term
isMatch
Definition
var object = { 'a': 1, 'b': 2 };

_.f(object, { 'b': 2 });
// => true

_.f(object, { 'b': 1 });
// => false
Term
isMatchWith
Definition
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' };

_.f(object, source, customizer);
// => true
Term
isNaN
Definition
_.f(NaN);
// => true

_.f(new Number(NaN));
// => true

isNaN(undefined);
// => true

_.f(undefined);
// => false
Term
isNative
Definition
_.f(Array.prototype.push);
// => true

_.f(_);
// => false
Term
isNil
Definition
_.f(null);
// => true

_.f(void 0);
// => true

_.f(NaN);
// => false
Term
isNull
Definition
_.f(null);
// => true

_.f(void 0);
// => false
Term
isNumber
Definition
_.f(3);
// => true

_.f(Number.MIN_VALUE);
// => true

_.f(Infinity);
// => true

_.f('3');
// => false
Term
isObject
Definition
_.f({});
// => true

_.f([1, 2, 3]);
// => true

_.f(_.noop);
// => true

_.f(null);
// => false
Term
isObjectLike
Definition
_.f({});
// => true

_.f([1, 2, 3]);
// => true

_.f(_.noop);
// => false

_.f(null);
// => false
Term
isPlainObject
Definition
function Foo() {
this.a = 1;
}

_.f(new Foo);
// => false

_.f([1, 2, 3]);
// => false

_.f({ 'x': 0, 'y': 0 });
// => true

_.f(Object.create(null));
// => true
Term
isRegExp
Definition
_.f(/abc/);
// => true

_.f('/abc/');
// => false
Term
isSafeInteger
Definition
_.f(3);
// => true

_.f(Number.MIN_VALUE);
// => false

_.f(Infinity);
// => false

_.f('3');
// => false
Term
isSet
Definition
_.f(new Set);
// => true

_.f(new WeakSet);
// => false
Term
isString
Definition
_.f('abc');
// => true

_.f(1);
// => false
Term
isSymbol
Definition
_.f(Symbol.iterator);
// => true

_.f('abc');
// => false
Term
isTypedArray
Definition
_.f(new Uint8Array);
// => true

_.f([]);
// => false
Term
isUndefined
Definition
_.f(void 0);
// => true

_.f(null);
// => false
Term
isWeakMap
Definition
_.f(new WeakMap);
// => true

_.f(new Map);
// => false
Term
isWeakSet
Definition
_.f(new WeakSet);
// => true

_.f(new Set);
// => false
Term
iteratee
Definition
var users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false }
];

// The `_.matches` iteratee shorthand.
_.filter(users, _.f({ 'user': 'barney', 'active': true }));
// => [{ 'user': 'barney', 'age': 36, 'active': true }]

// The `_.matchesProperty` iteratee shorthand.
_.filter(users, _.f(['user', 'fred']));
// => [{ 'user': 'fred', 'age': 40 }]

// The `_.property` iteratee shorthand.
_.map(users, _.f('user'));
// => ['barney', 'fred']

// Create custom iteratee shorthands.
_.f = _.wrap(_.iteratee, function(iteratee, func) {
return !_.isRegExp(func) ? iteratee(func) : function(string) {
return func.test(string);
};
});

_.filter(['abc', 'def'], /ef/);
// => ['def']
Term
join
Definition
_.f(['a', 'b', 'c'], '~');
// => 'a~b~c'
Term
kebabCase
Definition
_.f('Foo Bar');
// => 'foo-bar'

_.f('fooBar');
// => 'foo-bar'

_.f('__FOO_BAR__');
// => 'foo-bar'
Term
keyBy
Definition
var array = [
{ 'dir': 'left', 'code': 97 },
{ 'dir': 'right', 'code': 100 }
];

_.f(array, function(o) {
return String.fromCharCode(o.code);
});
// => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }

_.f(array, 'dir');
// => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
Term
keys
Definition
function Foo() {
this.a = 1;
this.b = 2;
}

Foo.prototype.c = 3;

_.f(new Foo);
// => ['a', 'b'] (iteration order is not guaranteed)

_.f('hi');
// => ['0', '1']
Term
keysIn
Definition
function Foo() {
this.a = 1;
this.b = 2;
}

Foo.prototype.c = 3;

_.f(new Foo);
// => ['a', 'b', 'c'] (iteration order is not guaranteed)
Term
last
Definition
_.f([1, 2, 3]);
// => 3
Term
lastIndexOf
Definition
_.f([1, 2, 1, 2], 2);
// => 3

// Search from the `fromIndex`.
_.f([1, 2, 1, 2], 2, 2);
// => 1
Term
lowerCase
Definition
_.f('--Foo-Bar--');
// => 'foo bar'

_.f('fooBar');
// => 'foo bar'

_.f('__FOO_BAR__');
// => 'foo bar'
Term
lowerFirst
Definition
_.f('Fred');
// => 'fred'

_.f('FRED');
// => 'fRED'
Term
lt
Definition
_.f(1, 3);
// => true

_.f(3, 3);
// => false

_.f(3, 1);
// => false
Term
lte
Definition
_.f(1, 3);
// => true

_.f(3, 3);
// => true

_.f(3, 1);
// => false
Term
map
Definition
function square(n) {
return n * n;
}

_.f([4, 8], square);
// => [16, 64]

_.f({ 'a': 4, 'b': 8 }, square);
// => [16, 64] (iteration order is not guaranteed)

var users = [
{ 'user': 'barney' },
{ 'user': 'fred' }
];

// The `_.property` iteratee shorthand.
_.f(users, 'user');
// => ['barney', 'fred']
Term
mapKeys
Definition
_.f({ 'a': 1, 'b': 2 }, function(value, key) {
return key + value;
});
// => { 'a1': 1, 'b2': 2 }
Term
mapValues
Definition
var users = {
'fred': { 'user': 'fred', 'age': 40 },
'pebbles': { 'user': 'pebbles', 'age': 1 }
};

_.f(users, function(o) { return o.age; });
// => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)

// The `_.property` iteratee shorthand.
_.f(users, 'age');
// => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
Term
matches
Definition
var objects = [
{ 'a': 1, 'b': 2, 'c': 3 },
{ 'a': 4, 'b': 5, 'c': 6 }
];

_.filter(objects, _.f({ 'a': 4, 'c': 6 }));
// => [{ 'a': 4, 'b': 5, 'c': 6 }]
Term
matchesProperty
Definition
var objects = [
{ 'a': 1, 'b': 2, 'c': 3 },
{ 'a': 4, 'b': 5, 'c': 6 }
];

_.find(objects, _.f('a', 4));
// => { 'a': 4, 'b': 5, 'c': 6 }
Term
max
Definition
_.f([4, 2, 8, 6]);
// => 8

_.f([]);
// => undefined
Term
maxBy
Definition
var objects = [{ 'n': 1 }, { 'n': 2 }];

_.f(objects, function(o) { return o.n; });
// => { 'n': 2 }

// The `_.property` iteratee shorthand.
_.f(objects, 'n');
// => { 'n': 2 }
Term
mean
Definition
_.f([4, 2, 8, 6]);
// => 5
Term
meanBy
Definition
var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];

_.f(objects, function(o) { return o.n; });
// => 5

// The `_.property` iteratee shorthand.
_.f(objects, 'n');
// => 5
Term
memoize
Definition
var object = { 'a': 1, 'b': 2 };
var other = { 'c': 3, 'd': 4 };

var values = _.f(_.values);
values(object);
// => [1, 2]

values(other);
// => [3, 4]

object.a = 2;
values(object);
// => [1, 2]

// Modify the result cache.
values.cache.set(object, ['a', 'b']);
values(object);
// => ['a', 'b']

// Replace `_.memoize.Cache`.
_.memoize.Cache = WeakMap;
Term
merge
Definition
var object = {
'a': [{ 'b': 2 }, { 'd': 4 }]
};

var other = {
'a': [{ 'c': 3 }, { 'e': 5 }]
};

_.f(object, other);
// => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
Term
mergeWith
Definition
function customizer(objValue, srcValue) {
if (_.isArray(objValue)) {
return objValue.concat(srcValue);
}
}

var object = { 'a': [1], 'b': [2] };
var other = { 'a': [3], 'b': [4] };

_.f(object, other, customizer);
// => { 'a': [1, 3], 'b': [2, 4] }
Term
method
Definition
var objects = [
{ 'a': { 'b': _.constant(2) } },
{ 'a': { 'b': _.constant(1) } }
];

_.map(objects, _.f('a.b'));
// => [2, 1]

_.map(objects, _.f(['a', 'b']));
// => [2, 1]
Term
methodOf
Definition
var array = _.times(3, _.constant),
object = { 'a': array, 'b': array, 'c': array };

_.map(['a[2]', 'c[0]'], _.f(object));
// => [2, 0]

_.map([['a', '2'], ['c', '0']], _.f(object));
// => [2, 0]
Term
min
Definition
_.f([4, 2, 8, 6]);
// => 2

_.f([]);
// => undefined
Term
minBy
Definition
var objects = [{ 'n': 1 }, { 'n': 2 }];

_.f(objects, function(o) { return o.n; });
// => { 'n': 1 }

// The `_.property` iteratee shorthand.
_.f(objects, 'n');
// => { 'n': 1 }
Term
mixin
Definition
function vowels(string) {
return _.filter(string, function(v) {
return /[aeiou]/i.test(v);
});
}

_.f({ 'vowels': vowels });
_.vowels('fred');
// => ['e']

_('fred').vowels().value();
// => ['e']

_.f({ 'vowels': vowels }, { 'chain': false });
_('fred').vowels();
// => ['e']
Term
multiply
Definition
_.f(6, 4);
// => 24
Term
negate
Definition
function isEven(n) {
return n % 2 == 0;
}

_.filter([1, 2, 3, 4, 5, 6], _.f(isEven));
// => [1, 3, 5]
Term
noConflict
Definition
var lodash = _.f();
Term
noop
Definition
_.times(2, _.f);
// => [undefined, undefined]
Term
now
Definition
_.defer(function(stamp) {
console.log(_.now() - stamp);
}, _.f());
// => Logs the number of milliseconds it took for the deferred invocation.
Term
nth
Definition
var array = ['a', 'b', 'c', 'd'];

_.f(array, 1);
// => 'b'

_.f(array, -2);
// => 'c';
Term
nthArg
Definition
var func = _.f(1);
func('a', 'b', 'c', 'd');
// => 'b'

var func = _.f(-2);
func('a', 'b', 'c', 'd');
// => 'c'
Term
omit
Definition
var object = { 'a': 1, 'b': '2', 'c': 3 };

_.f(object, ['a', 'c']);
// => { 'b': '2' }
Term
omitBy
Definition
var object = { 'a': 1, 'b': '2', 'c': 3 };

_.f(object, _.isNumber);
// => { 'b': '2' }
Term
once
Definition
var initialize = _.f(createApplication);
initialize();
initialize();
// => `createApplication` is invoked once
Term
orderBy
Definition
var users = [
{ 'user': 'fred', 'age': 48 },
{ 'user': 'barney', 'age': 34 },
{ 'user': 'fred', 'age': 40 },
{ 'user': 'barney', 'age': 36 }
];

// Sort by `user` in ascending order and by `age` in descending order.
_.f(users, ['user', 'age'], ['asc', 'desc']);
// => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
Term
over
Definition
var func = _.f([Math.max, Math.min]);

func(1, 2, 3, 4);
// => [4, 1]
Term
overArgs
Definition
function doubled(n) {
return n * 2;
}

function square(n) {
return n * n;
}

var func = _.f(function(x, y) {
return [x, y];
}, [square, doubled]);

func(9, 3);
// => [81, 6]

func(10, 5);
// => [100, 10]
Term
overEvery
Definition
var func = _.f([Boolean, isFinite]);

func('1');
// => true

func(null);
// => false

func(NaN);
// => false
Term
overSome
Definition
var func = _.f([Boolean, isFinite]);

func('1');
// => true

func(null);
// => true

func(NaN);
// => false
Term
pad
Definition
_.f('abc', 8);
// => ' abc '

_.f('abc', 8, '_-');
// => '_-abc_-_'

_.f('abc', 3);
// => 'abc'
Term
padEnd
Definition
_.f('abc', 6);
// => 'abc '

_.f('abc', 6, '_-');
// => 'abc_-_'

_.f('abc', 3);
// => 'abc'
Term
padStart
Definition
_.f('abc', 6);
// => ' abc'

_.f('abc', 6, '_-');
// => '_-_abc'

_.f('abc', 3);
// => 'abc'
Term
parseInt
Definition
_.f('08');
// => 8

_.map(['6', '08', '10'], _.f);
// => [6, 8, 10]
Term
partial
Definition
function greet(greeting, name) {
return greeting + ' ' + name;
}

var sayHelloTo = _.f(greet, 'hello');
sayHelloTo('fred');
// => 'hello fred'

// Partially applied with placeholders.
var greetFred = _.f(greet, _, 'fred');
greetFred('hi');
// => 'hi fred'
Term
partialRight
Definition
function greet(greeting, name) {
return greeting + ' ' + name;
}

var greetFred = _.f(greet, 'fred');
greetFred('hi');
// => 'hi fred'

// Partially applied with placeholders.
var sayHelloTo = _.f(greet, 'hello', _);
sayHelloTo('fred');
// => 'hello fred'
Term
partition
Definition
var users = [
{ 'user': 'barney', 'age': 36, 'active': false },
{ 'user': 'fred', 'age': 40, 'active': true },
{ 'user': 'pebbles', 'age': 1, 'active': false }
];

_.f(users, function(o) { return o.active; });
// => objects for [['fred'], ['barney', 'pebbles']]

// The `_.matches` iteratee shorthand.
_.f(users, { 'age': 1, 'active': false });
// => objects for [['pebbles'], ['barney', 'fred']]

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => objects for [['barney', 'pebbles'], ['fred']]

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => objects for [['fred'], ['barney', 'pebbles']]
Term
pick
Definition
var object = { 'a': 1, 'b': '2', 'c': 3 };

_.f(object, ['a', 'c']);
// => { 'a': 1, 'c': 3 }
Term
pickBy
Definition
var object = { 'a': 1, 'b': '2', 'c': 3 };

_.f(object, _.isNumber);
// => { 'a': 1, 'c': 3 }
Term
property
Definition
var objects = [
{ 'a': { 'b': 2 } },
{ 'a': { 'b': 1 } }
];

_.map(objects, _.f('a.b'));
// => [2, 1]

_.map(_.sortBy(objects, _.f(['a', 'b'])), 'a.b');
// => [1, 2]
Term
propertyOf
Definition
var array = [0, 1, 2],
object = { 'a': array, 'b': array, 'c': array };

_.map(['a[2]', 'c[0]'], _.f(object));
// => [2, 0]

_.map([['a', '2'], ['c', '0']], _.f(object));
// => [2, 0]
Term
prototype
Definition
var wrapped = f([1, 2]);

wrapped[Symbol.iterator]() === wrapped;
// => true

Array.from(wrapped);
// => [1, 2]
Term
prototype.at
Definition
var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };

f(object).f(['a[0].b.c', 'a[1]']).value();
// => [3, 4]
Term
prototype.chain
Definition
var users = [
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 }
];

// A sequence without explicit chaining.
f(users).head();
// => { 'user': 'barney', 'age': 36 }

// A sequence with explicit chaining.
f(users)
.f()
.head()
.pick('user')
.value();
// => { 'user': 'barney' }
Term
prototype.commit
Definition
var array = [1, 2];
var wrapped = f(array).push(3);

console.log(array);
// => [1, 2]

wrapped = wrapped.f();
console.log(array);
// => [1, 2, 3]

wrapped.last();
// => 3

console.log(array);
// => [1, 2, 3]
Term
prototype.next
Definition
var wrapped = f([1, 2]);

wrapped.f();
// => { 'done': false, 'value': 1 }

wrapped.f();
// => { 'done': false, 'value': 2 }

wrapped.f();
// => { 'done': true, 'value': undefined }
Term
prototype.plant
Definition
function square(n) {
return n * n;
}

var wrapped = f([1, 2]).map(square);
var other = wrapped.f([3, 4]);

other.value();
// => [9, 16]

wrapped.value();
// => [1, 4]
Term
prototype.reverse
Definition
var array = [1, 2, 3];

f(array).f().value()
// => [3, 2, 1]

console.log(array);
// => [3, 2, 1]
Term
prototype.value
Definition
f([1, 2, 3]).f();
// => [1, 2, 3]
Term
pull
Definition
var array = ['a', 'b', 'c', 'a', 'b', 'c'];

_.f(array, 'a', 'c');
console.log(array);
// => ['b', 'b']
Term
pullAll
Definition
var array = ['a', 'b', 'c', 'a', 'b', 'c'];

_.f(array, ['a', 'c']);
console.log(array);
// => ['b', 'b']
Term
pullAllBy
Definition
var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];

_.f(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
console.log(array);
// => [{ 'x': 2 }]
Term
pullAllWith
Definition
var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];

_.f(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
console.log(array);
// => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
Term
pullAt
Definition
var array = ['a', 'b', 'c', 'd'];
var pulled = _.f(array, [1, 3]);

console.log(array);
// => ['a', 'c']

console.log(pulled);
// => ['b', 'd']
Term
random
Definition
_.f(0, 5);
// => an integer between 0 and 5

_.f(5);
// => also an integer between 0 and 5

_.f(5, true);
// => a floating-point number between 0 and 5

_.f(1.2, 5.2);
// => a floating-point number between 1.2 and 5.2
Term
range
Definition
_.f(4);
// => [0, 1, 2, 3]

_.f(-4);
// => [0, -1, -2, -3]

_.f(1, 5);
// => [1, 2, 3, 4]

_.f(0, 20, 5);
// => [0, 5, 10, 15]

_.f(0, -4, -1);
// => [0, -1, -2, -3]

_.f(1, 4, 0);
// => [1, 1, 1]

_.f(0);
// => []
Term
rangeRight
Definition
_.f(4);
// => [3, 2, 1, 0]

_.f(-4);
// => [-3, -2, -1, 0]

_.f(1, 5);
// => [4, 3, 2, 1]

_.f(0, 20, 5);
// => [15, 10, 5, 0]

_.f(0, -4, -1);
// => [-3, -2, -1, 0]

_.f(1, 4, 0);
// => [1, 1, 1]

_.f(0);
// => []
Term
rearg
Definition
var rearged = _.f(function(a, b, c) {
return [a, b, c];
}, [2, 0, 1]);

rearged('b', 'c', 'a')
// => ['a', 'b', 'c']
Term
reduce
Definition
_.f([1, 2], function(sum, n) {
return sum + n;
}, 0);
// => 3

_.f({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
(result[value] || (result[value] = [])).push(key);
return result;
}, {});
// => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
Term
reduceRight
Definition
var array = [[0, 1], [2, 3], [4, 5]];

_.f(array, function(flattened, other) {
return flattened.concat(other);
}, []);
// => [4, 5, 2, 3, 0, 1]
Term
reject
Definition
var users = [
{ 'user': 'barney', 'age': 36, 'active': false },
{ 'user': 'fred', 'age': 40, 'active': true }
];

_.f(users, function(o) { return !o.active; });
// => objects for ['fred']

// The `_.matches` iteratee shorthand.
_.f(users, { 'age': 40, 'active': true });
// => objects for ['barney']

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => objects for ['fred']

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => objects for ['barney']
Term
remove
Definition
var array = [1, 2, 3, 4];
var evens = _.f(array, function(n) {
return n % 2 == 0;
});

console.log(array);
// => [1, 3]

console.log(evens);
// => [2, 4]
Term
repeat
Definition
_.f('*', 3);
// => '***'

_.f('abc', 2);
// => 'abcabc'

_.f('abc', 0);
// => ''
Term
replace
Definition
_.f('Hi Fred', 'Fred', 'Barney');
// => 'Hi Barney'
Term
rest
Definition
var say = _.f(function(what, names) {
return what + ' ' + _.initial(names).join(', ') +
(_.size(names) > 1 ? ', & ' : '') + _.last(names);
});

say('hello', 'fred', 'barney', 'pebbles');
// => 'hello fred, barney, & pebbles'
Term
result
Definition
var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };

_.f(object, 'a[0].b.c1');
// => 3

_.f(object, 'a[0].b.c2');
// => 4

_.f(object, 'a[0].b.c3', 'default');
// => 'default'

_.f(object, 'a[0].b.c3', _.constant('default'));
// => 'default'
Term
reverse
Definition
var array = [1, 2, 3];

_.f(array);
// => [3, 2, 1]

console.log(array);
// => [3, 2, 1]
Term
round
Definition
_.f(4.006);
// => 4

_.f(4.006, 2);
// => 4.01

_.f(4060, -2);
// => 4100
Term
runInContext
Definition
_.mixin({ 'foo': _.constant('foo') });

var lodash = _.f();
lodash.mixin({ 'bar': lodash.constant('bar') });

_.isFunction(_.foo);
// => true
_.isFunction(_.bar);
// => false

lodash.isFunction(lodash.foo);
// => false
lodash.isFunction(lodash.bar);
// => true

// Create a suped-up `defer` in Node.js.
var defer = _.f({ 'setTimeout': setImmediate }).defer;
Term
sample
Definition
_.f([1, 2, 3, 4]);
// => 2
Term
sampleSize
Definition
_.f([1, 2, 3], 2);
// => [3, 1]

_.f([1, 2, 3], 4);
// => [2, 3, 1]
Term
set
Definition
var object = { 'a': [{ 'b': { 'c': 3 } }] };

_.f(object, 'a[0].b.c', 4);
console.log(object.a[0].b.c);
// => 4

_.f(object, ['x', '0', 'y', 'z'], 5);
console.log(object.x[0].y.z);
// => 5
Term
setWith
Definition
var object = {};

_.f(object, '[0][1]', 'a', Object);
// => { '0': { '1': 'a' } }
Term
shuffle
Definition
_.f([1, 2, 3, 4]);
// => [4, 1, 3, 2]
Term
size
Definition
_.f([1, 2, 3]);
// => 3

_.size({ 'a': 1, 'b': 2 });
// => 2

_.f('pebbles');
// => 7
Term
slice
Definition
var array = [1, 2, 3];

_.f(array, 1, 2);
// => [2]
Term
snakeCase
Definition
_.f('Foo Bar');
// => 'foo_bar'

_.f('fooBar');
// => 'foo_bar'

_.f('--FOO-BAR--');
// => 'foo_bar'
Term
some
Definition
_.f([null, 0, 'yes', false], Boolean);
// => true

var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false }
];

// The `_.matches` iteratee shorthand.
_.f(users, { 'user': 'barney', 'active': false });
// => false

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => true

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => true
Term
sortBy
Definition
var users = [
{ 'user': 'fred', 'age': 48 },
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 },
{ 'user': 'barney', 'age': 34 }
];

_.f(users, [function(o) { return o.user; }]);
// => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]

_.f(users, ['user', 'age']);
// => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
Term
sortedIndex
Definition
_.f([30, 50], 40);
// => 1
Term
sortedIndexBy
Definition
var objects = [{ 'x': 4 }, { 'x': 5 }];

_.f(objects, { 'x': 4 }, function(o) { return o.x; });
// => 0

// The `_.property` iteratee shorthand.
_.f(objects, { 'x': 4 }, 'x');
// => 0
Term
sortedIndexOf
Definition
_.f([4, 5, 5, 5, 6], 5);
// => 1
Term
sortedLastIndex
Definition
_.f([4, 5, 5, 5, 6], 5);
// => 4
Term
sortedLastIndexBy
Definition
var objects = [{ 'x': 4 }, { 'x': 5 }];

_.f(objects, { 'x': 4 }, function(o) { return o.x; });
// => 1

// The `_.property` iteratee shorthand.
_.f(objects, { 'x': 4 }, 'x');
// => 1
Term
sortedLastIndexOf
Definition
_.f([4, 5, 5, 5, 6], 5);
// => 3
Term
sortedUniq
Definition
_.f([1, 1, 2]);
// => [1, 2]
Term
sortedUniqBy
Definition
_.f([1.1, 1.2, 2.3, 2.4], Math.floor);
// => [1.1, 2.3]
Term
split
Definition
_.f('a-b-c', '-', 2);
// => ['a', 'b']
Term
spread
Definition
var say = _.f(function(who, what) {
return who + ' says ' + what;
});

say(['fred', 'hello']);
// => 'fred says hello'

var numbers = Promise.all([
Promise.resolve(40),
Promise.resolve(36)
]);

numbers.then(_.f(function(x, y) {
return x + y;
}));
// => a Promise of 76
Term
startCase
Definition
_.f('--foo-bar--');
// => 'Foo Bar'

_.f('fooBar');
// => 'Foo Bar'

_.f('__FOO_BAR__');
// => 'FOO BAR'
Term
startsWith
Definition
_.f('abc', 'a');
// => true

_.f('abc', 'b');
// => false

_.f('abc', 'b', 1);
// => true
Term
stubArray
Definition
var arrays = _.times(2, _.f);

console.log(arrays);
// => [[], []]

console.log(arrays[0] === arrays[1]);
// => false
Term
stubFalse
Definition
_.times(2, _.f);
// => [false, false]
Term
stubObject
Definition
var objects = _.times(2, _.f);

console.log(objects);
// => [{}, {}]

console.log(objects[0] === objects[1]);
// => false
Term
stubString
Definition
_.times(2, _.f);
// => ['', '']
Term
stubTrue
Definition
_.times(2, _.f);
// => [true, true]
Term
subtract
Definition
_.f(6, 4);
// => 2
Term
sum
Definition
_.f([4, 2, 8, 6]);
// => 20
Term
sumBy
Definition
var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];

_.f(objects, function(o) { return o.n; });
// => 20

// The `_.property` iteratee shorthand.
_.f(objects, 'n');
// => 20
Term
tail
Definition
_.f([1, 2, 3]);
// => [2, 3]
Term
take
Definition
_.f([1, 2, 3]);
// => [1]

_.f([1, 2, 3], 2);
// => [1, 2]

_.f([1, 2, 3], 5);
// => [1, 2, 3]

_.f([1, 2, 3], 0);
// => []
Term
takeRight
Definition
_.f([1, 2, 3]);
// => [3]

_.f([1, 2, 3], 2);
// => [2, 3]

_.f([1, 2, 3], 5);
// => [1, 2, 3]

_.f([1, 2, 3], 0);
// => []
Term
takeRightWhile
Definition
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': false }
];

_.f(users, function(o) { return !o.active; });
// => objects for ['fred', 'pebbles']

// The `_.matches` iteratee shorthand.
_.f(users, { 'user': 'pebbles', 'active': false });
// => objects for ['pebbles']

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => objects for ['fred', 'pebbles']

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => []
Term
takeWhile
Definition
var users = [
{ 'user': 'barney', 'active': false },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': true }
];

_.f(users, function(o) { return !o.active; });
// => objects for ['barney', 'fred']

// The `_.matches` iteratee shorthand.
_.f(users, { 'user': 'barney', 'active': false });
// => objects for ['barney']

// The `_.matchesProperty` iteratee shorthand.
_.f(users, ['active', false]);
// => objects for ['barney', 'fred']

// The `_.property` iteratee shorthand.
_.f(users, 'active');
// => []
Term
tap
Definition
_([1, 2, 3])
.f(function(array) {
// Mutate input array.
array.pop();
})
.reverse()
.value();
// => [2, 1]
Term
template
Definition

// Use the "interpolate" delimiter to create a compiled template.

var compiled = _.f('hello <%= user %>!');

compiled({ 'user': 'fred' });

// => 'hello fred!'

 

// Use the HTML "escape" delimiter to escape data property values.

var compiled = _.f('<b><%- value %></b>');

compiled({ 'value': '<script>' });

// => '<b>&lt;script&gt;</b>'

 

// Use the "evaluate" delimiter to execute JavaScript and generate HTML.

var compiled = _.f('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');

compiled({ 'users': ['fred', 'barney'] });

// => '<li>fred</li><li>barney</li>'

 

// Use the internal `print` function in "evaluate" delimiters.

var compiled = _.f('<% print("hello " + user); %>!');

compiled({ 'user': 'barney' });

// => 'hello barney!'

 

// Use the ES template literal delimiter as an "interpolate" delimiter.

// Disable support by replacing the "interpolate" delimiter.

var compiled = _.f('hello ${ user }!');

compiled({ 'user': 'pebbles' });

// => 'hello pebbles!'

 

// Use backslashes to treat delimiters as plain text.

var compiled = _.f('<%= "\\<%- value %\\>" %>');

compiled({ 'value': 'ignored' });

// => '<%- value %>'

 

// Use the `imports` option to import `jQuery` as `jq`.

var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';

var compiled = _.f(text, { 'imports': { 'jq': jQuery } });

compiled({ 'users': ['fred', 'barney'] });

// => '<li>fred</li><li>barney</li>'

 

// Use the `sourceURL` option to specify a custom sourceURL for the template.

var compiled = _.f('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });

compiled(data);

// => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.

 

// Use the `variable` option to ensure a with-statement isn't used in the compiled template.

var compiled = _.f('hi <%= data.user %>!', { 'variable': 'data' });

compiled.source;

// => function(data) {

//   var __t, __p = '';

//   __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';

//   return __p;

// }

 

// Use custom template delimiters.

_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;

var compiled = _.f('hello {{ user }}!');

compiled({ 'user': 'mustache' });

// => 'hello mustache!'

 

// Use the `source` property to inline compiled templates for meaningful

// line numbers in error messages and stack traces.

fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\

  var JST = {\

    "main": ' + _.f(mainText).source + '\

  };\

');

Term
templateSettings
Definition
Used to change template delimiters.
Term
templateSettings.escape
Definition
Used to detect data property values to be HTML-escaped.
Term
templateSettings.evaluate
Definition
Used to detect code to be evaluated.
Term
templateSettings.imports
Definition
Used to import variables into the compiled template.
Term
templateSettings.imports._
Definition
A reference to the lodash function.
Term
templateSettings.interpolate
Definition
Used to detect data property values to inject.
Term
templateSettings.variable
Definition
Used to reference the data object in the template text.
Term
throttle
Definition
// Avoid excessively updating the position while scrolling.
jQuery(window).on('scroll', _.f(updatePosition, 100));

// Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
var throttled = _.f(renewToken, 300000, { 'trailing': false });
jQuery(element).on('click', throttled);

// Cancel the trailing throttled invocation.
jQuery(window).on('popstate', throttled.cancel);
Term
thru
Definition
_(' abc ')
.chain()
.trim()
.f(function(value) {
return [value];
})
.value();
// => ['abc']
Term
times
Definition
_.f(3, String);
// => ['0', '1', '2']

_.f(4, _.constant(0));
// => [0, 0, 0, 0]
Term
toArray
Definition
_.f({ 'a': 1, 'b': 2 });
// => [1, 2]

_.f('abc');
// => ['a', 'b', 'c']

_.f(1);
// => []

_.f(null);
// => []
Term
toFinite
Definition
_.f(3.2);
// => 3.2

_.f(Number.MIN_VALUE);
// => 5e-324

_.f(Infinity);
// => 1.7976931348623157e+308

_.f('3.2');
// => 3.2
Term
toInteger
Definition
_.f(3.2);
// => 3

_.f(Number.MIN_VALUE);
// => 0

_.f(Infinity);
// => 1.7976931348623157e+308

_.f('3.2');
// => 3
Term
toLength
Definition
_.f(3.2);
// => 3

_.f(Number.MIN_VALUE);
// => 0

_.f(Infinity);
// => 4294967295

_.f('3.2');
// => 3
Term
toLower
Definition
_.f('--Foo-Bar--');
// => '--foo-bar--'

_.f('fooBar');
// => 'foobar'

_.f('__FOO_BAR__');
// => '__foo_bar__'
Term
toNumber
Definition
_.f(3.2);
// => 3.2

_.f(Number.MIN_VALUE);
// => 5e-324

_.f(Infinity);
// => Infinity

_.f('3.2');
// => 3.2
Term
toPairs
Definition
function Foo() {
this.a = 1;
this.b = 2;
}

Foo.prototype.c = 3;

_.f(new Foo);
// => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
Term
toPairsIn
Definition
function Foo() {
this.a = 1;
this.b = 2;
}

Foo.prototype.c = 3;

_.f(new Foo);
// => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
Term
toPath
Definition
_.f('a.b.c');
// => ['a', 'b', 'c']

_.f('a[0].b.c');
// => ['a', '0', 'b', 'c']
Term
toPlainObject
Definition
function Foo() {
this.b = 2;
}

Foo.prototype.c = 3;

_.assign({ 'a': 1 }, new Foo);
// => { 'a': 1, 'b': 2 }

_.assign({ 'a': 1 }, _.f(new Foo));
// => { 'a': 1, 'b': 2, 'c': 3 }
Term
toSafeInteger
Definition
_.f(3.2);
// => 3

_.f(Number.MIN_VALUE);
// => 0

_.f(Infinity);
// => 9007199254740991

_.f('3.2');
// => 3
Term
toString
Definition
_.f(null);
// => ''

_.f(-0);
// => '-0'

_.f([1, 2, 3]);
// => '1,2,3'
Term
toUpper
Definition
_.f('--foo-bar--');
// => '--FOO-BAR--'

_.f('fooBar');
// => 'FOOBAR'

_.f('__foo_bar__');
// => '__FOO_BAR__'
Term
transform
Definition
_.f([2, 3, 4], function(result, n) {
result.push(n *= n);
return n % 2 == 0;
}, []);
// => [4, 9]

_.f({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
(result[value] || (result[value] = [])).push(key);
}, {});
// => { '1': ['a', 'c'], '2': ['b'] }
Term
trim
Definition
_.f(' abc ');
// => 'abc'

_.f('-_-abc-_-', '_-');
// => 'abc'

_.map([' foo ', ' bar '], _.f);
// => ['foo', 'bar']
Term
trimEnd
Definition
_.f(' abc ');
// => ' abc'

_.f('-_-abc-_-', '_-');
// => '-_-abc'
Term
trimStart
Definition
_.f(' abc ');
// => 'abc '

_.f('-_-abc-_-', '_-');
// => 'abc-_-'
Term
truncate
Definition
_.f('hi-diddly-ho there, neighborino');
// => 'hi-diddly-ho there, neighbo...'

_.f('hi-diddly-ho there, neighborino', {
'length': 24,
'separator': ' '
});
// => 'hi-diddly-ho there,...'

_.f('hi-diddly-ho there, neighborino', {
'length': 24,
'separator': /,? +/
});
// => 'hi-diddly-ho there...'

_.f('hi-diddly-ho there, neighborino', {
'omission': ' [...]'
});
// => 'hi-diddly-ho there, neig [...]'
Term
unary
Definition
_.map(['6', '8', '10'], _.f(parseInt));
// => [6, 8, 10]
Term
unescape
Definition
_.f('fred, barney, & pebbles');
// => 'fred, barney, & pebbles'
Term
union
Definition
_.f([2], [1, 2]);
// => [2, 1]
Term
unionBy
Definition
_.f([2.1], [1.2, 2.3], Math.floor);
// => [2.1, 1.2]

// The `_.property` iteratee shorthand.
_.f([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }, { 'x': 2 }]
Term
unionWith
Definition
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];

_.f(objects, others, _.isEqual);
// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
Term
uniq
Definition
_.f([2, 1, 2]);
// => [2, 1]
Term
uniqBy
Definition
_.f([2.1, 1.2, 2.3], Math.floor);
// => [2.1, 1.2]

// The `_.property` iteratee shorthand.
_.f([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }, { 'x': 2 }]
Term
uniqWith
Definition
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];

_.f(objects, _.isEqual);
// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
Term
uniqueId
Definition
_.f('contact_');
// => 'contact_104'

_.f();
// => '105'
Term
unset
Definition
var object = { 'a': [{ 'b': { 'c': 7 } }] };
_.f(object, 'a[0].b.c');
// => true

console.log(object);
// => { 'a': [{ 'b': {} }] };

_.f(object, ['a', '0', 'b', 'c']);
// => true

console.log(object);
// => { 'a': [{ 'b': {} }] };
Term
unzip
Definition
var array = [['a', 1, true], ['b', 2, false]];

_.f(array);
// => [['a', 'b'], [1, 2], [true, false]]
Term
unzipWith
Definition
var array = [[1, 10, 100], [2, 20, 200]];

_.f(array, _.add);
// => [3, 30, 300]
Term
update
Definition
var object = { 'a': [{ 'b': { 'c': 3 } }] };

_.f(object, 'a[0].b.c', function(n) { return n * n; });
console.log(object.a[0].b.c);
// => 9

_.f(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
console.log(object.x[0].y.z);
// => 0
Term
updateWith
Definition
var object = {};

_.f(object, '[0][1]', _.constant('a'), Object);
// => { '0': { '1': 'a' } }
Term
upperCase
Definition
_.f('--foo-bar');
// => 'FOO BAR'

_.f('fooBar');
// => 'FOO BAR'

_.f('__foo_bar__');
// => 'FOO BAR'
Term
upperFirst
Definition
_.f('fred');
// => 'Fred'

_.f('FRED');
// => 'FRED'
Term
values
Definition
function Foo() {
this.a = 1;
this.b = 2;
}

Foo.prototype.c = 3;

_.f(new Foo);
// => [1, 2] (iteration order is not guaranteed)

_.f('hi');
// => ['h', 'i']
Term
valuesIn
Definition
function Foo() {
this.a = 1;
this.b = 2;
}

Foo.prototype.c = 3;

_.f(new Foo);
// => [1, 2, 3] (iteration order is not guaranteed)
Term
without
Definition
_.f([2, 1, 2, 3], 1, 2);
// => [3]
Term
words
Definition
_.f('fred, barney, & pebbles');
// => ['fred', 'barney', 'pebbles']

_.f('fred, barney, & pebbles', /[^, ]+/g);
// => ['fred', 'barney', '&', 'pebbles']
Term
wrap
Definition
var p = _.f(_.escape, function(func, text) { return '

' + func(text) + '

'; }); p('fred, barney, & pebbles'); // => '

fred, barney, & pebbles

'
Term
xor
Definition
_.f([2, 1], [2, 3]);
// => [1, 3]
Term
xorBy
Definition
_.f([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [1.2, 3.4]

// The `_.property` iteratee shorthand.
_.f([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 2 }]
Term
xorWith
Definition
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];

_.f(objects, others, _.isEqual);
// => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
Term
zip
Definition
_.f(['a', 'b'], [1, 2], [true, false]);
// => [['a', 1, true], ['b', 2, false]]
Term
zipObject
Definition
_.f(['a', 'b'], [1, 2]);
// => { 'a': 1, 'b': 2 }
Term
zipObjectDeep
Definition
_.f(['a.b[0].c', 'a.b[1].d'], [1, 2]);
// => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
Term
zipWith
Definition
_.f([1, 2], [10, 20], [100, 200], function(a, b, c) {
return a + b + c;
});
// => [111, 222]
Supporting users have an ad free experience!