Last Updated : 03 Sep, 2024
Lodash _.spread() method is used to create a function that calls the given function as a parameter using this binding of the create function, along with an array of arguments. It is based on the spread operator in JavaScript.
Syntax:_.spread(func, start);Parameters:
Example 1: In this example, we are passing two strings in a function and printing the result in the console by the use of the lodash _.spread() method.
JavaScript
// Requiring lodash library
const _ = require('lodash');
// Using the _.spread() method with its parameter
let write = _.spread(function (author, portal) {
return author + ' writes for ' + portal + '!';
});
// Calling write with its values
console.log(write(['Nidhi', 'GeeksforGeeks']));
Output:
Nidhi writes for GeeksforGeeks!
Example 2: In this example, we are passing two numbers in a addition function and printing the result in the console by the use of the lodash _.spread() method.
JavaScript
// Requiring lodash library
const _ = require('lodash');
// Using the _.spread() method with its parameter
let addition = _.spread(function (x, y) {
return x + y;
});
// Calling addition with its values
console.log(addition([56, 44]));
Output:
100
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4