A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-prototype-chain-method/ below:

Lodash _.prototype.chain() Method - GeeksforGeeks

Lodash _.prototype.chain() Method

Last Updated : 03 Nov, 2023

Lodash _.prototype.chain() method of Sequence in lodash is used to create an instance of lodash wrapper accompanied by explicit method chain sequences enabled.

Syntax:
_.prototype.chain();
Parameters:

This method doesn't accept any parameter.

Return Value:

This method returns the new lodash wrapper instance.

Example 1: In this example, we are chaining the given array and getting the tail value by the use of the lodash _.prototype.chain() method.

JavaScript
// Requiring lodash library
const _ = require('lodash');

// Initializing authors variable
let authors = [
    { 'author': 'Nidhi', 'articles': 750 },
    { 'author': 'Nisha', 'articles': 500 }
];

// Calling chain() method and creating
// an explicit chaining sequence
let result = _(authors).chain()
    .tail()
    .value();

// Displays output                       
console.log(result);

Output:

[ { author: 'Nisha', articles: 500 } ]

Example 2: In this example, we are chaining the given array and getting the head value having article as a key by the use of the lodash _.prototype.chain() method.

JavaScript
// Requiring lodash library
const _ = require('lodash');

// Initializing authors variable
let authors = [
    { 'author': 'Nidhi', 'articles': 750 },
    { 'author': 'Nisha', 'articles': 500 }
];

// Calling chain() method and creating
// an explicit chaining sequence
let result = _(authors).chain()
    .head()
    .pick('articles')
    .value();

// Displays output                       
console.log(result);

Output:

{ articles: 750 }

Example 3: In this example, we are chaining the given string by the use of the lodash _.prototype.chain() method.

JavaScript
// Requiring lodash library
const _ = require('lodash');

// Calling chain() method and creating
// an explicit chaining sequence
let obj = _("GeeksforGeeks").chain().value();

// Displays output                       
console.log(obj[0]);
console.log(obj[4]);
console.log(obj[7]);
console.log(obj[11]);

Output:

G
s
r
k

Reference: https://lodash.com/docs/4.17.15#prototype-chain



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