General Utility Functions in Lodash
Lodash provides a variety of general-purpose utility functions. Here are some commonly used utility methods:
Invokes the iteratee n
times, returning an array of the results of each invocation.
_.times(3, String);
// => ['0', '1', '2']
_.times(4, () => 0);
// => [0, 0, 0, 0]
Produces a random number between the inclusive lower
and upper
bounds.
_.random(0, 5);
// => an integer between 0 and 5
_.random(5);
// => also an integer between 0 and 5
_.random(1.2, 5.2);
// => a floating-point number between 1.2 and 5.2
Generates a unique ID. If prefix
is given, the ID is appended to it.
_.uniqueId('contact_');
// => 'contact_104'
_.uniqueId();
// => '105'
Previous: String Methods Next: Chaining
Last updated 1 day ago