lodash.restparam

3.6.1 · deprecated · verified Tue Apr 21

This package provides a modular build of Lodash's `_.restParam` function, designed to create a new function that collects arguments from a specified position into an array. While `lodash.restparam` is at version 3.6.1, the broader Lodash ecosystem has progressed to version 4.x. In Lodash v4.0.0, the `_.restParam` function was renamed to `_.rest`. Furthermore, all individual, per-method `lodash.*` packages, including `lodash.restparam`, are officially discouraged by the Lodash team and are slated for removal in Lodash v5. Modern JavaScript (ES6+) introduced native rest parameters (`...args`), which largely supersede the functionality provided by `_.restParam`. The package is unmaintained and should generally be avoided in favor of native features or direct imports from the main `lodash` package.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the usage of `lodash.restparam` to create a function that handles a variable number of arguments, alongside its modern native JavaScript equivalent.

import restParam from 'lodash.restparam';

const greetWithManyNames = restParam(function(greeting, ...names) {
  return `${greeting} ${names.join(', ')}!`;
}, 1); // Collect all arguments from index 1 (the second argument) onwards

console.log(greetWithManyNames('Hello', 'Alice', 'Bob', 'Charlie'));
// Expected output: "Hello Alice, Bob, Charlie!"

// Demonstrating the equivalent with native rest parameters, preferred in modern JS:
function modernGreet(greeting, ...names) {
  return `${greeting} ${names.join(', ')}!`;
}
console.log(modernGreet('Hi', 'David', 'Eve'));
// Expected output: "Hi David, Eve!"

view raw JSON →