Last Updated : 03 Nov, 2023
Lodash _.thru() method of Sequence in lodash is similar to _.tap() method and the only difference is that it returns the outcome of the interceptor. Moreover, this method is mainly used to “pass thru” values in a method chain sequence by replacing intermediate results.
Syntax:_.thru(value, interceptor);Parameters:
This method returns the result of the interceptor.
Example 1: In this example, we are getting a value as an array because of the use of the lodash _.thru() method.
JavaScript
// Requiring lodash library
const _ = require('lodash');
// Calling thru() method
let result = _(144).thru(function (value) {
return [value];
}).value();
// Displays output
console.log(result);
Output:
[ 144 ]
Example 2: In this example, we are getting a value as an array because of the use of the lodash _.thru() method.
JavaScript
// Requiring lodash library
const _ = require('lodash');
// Calling thru() method
let result = _('GfG').thru(function (value) {
return [value];
}).value();
// Displays output
console.log(result);
Output:
[ 'GfG' ]
Example 3: In this example, we are getting an array of array because of the use of the lodash _.thru() method.
JavaScript
// Requiring lodash library
const _ = require('lodash');
// Defining value
let val = ['g', 'f', 'G']
// Calling thru() method along with
// reverse and chain method
let result = _(val).reverse()
.chain()
.thru(function (value) {
return [value];
})
.value();
// Displays output
console.log(result);
Output:
[ [ 'G', 'f', 'g' ] ]
Reference: https://lodash.com/docs/4.17.15#thru
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