A RetroSearch Logo

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

Search Query:

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

Lodash _.takeRightWhile() Method - GeeksforGeeks

Lodash _.takeRightWhile() Method

Last Updated : 02 Sep, 2024

Lodash _.takeRightWhile the method is used to create a slice of an array in which elements are taken from the end and these elements are taken until the predicate returns falsely.

Syntax:
_.takeRightWhile(array, [predicate=_.identity]);
Parameters: Return Value:

Example 1: In this example, we are getting an array of objects that satisfy the given condition in a function.

javascript
// Requiring the lodash library 
const _ = require("lodash");

// Original array 
let users = [{
    'user': 'fred', 'active': false
},
{ 'user': 'pebbles', 'active': false }];

// Use of _.takeRightWhile() 
// method 
let ind = _.takeRightWhile(users, function (o) {
    return !o.active;
});

// Printing the output 
console.log(ind);

Output:

[{ user: 'fred', active: false }, {user: 'pebbles', active: false}]

Example 2: In this example, we are getting an array of objects that satisfy the given condition in a function.

javascript
// Requiring the lodash library 
const _ = require("lodash");

// Original array 
let users = [{
    'user': 'fred', 'active': false
},
{ 'user': 'pebbles', 'active': false }];

// Use of _.takeRightWhile() 
// method 
// The `_.matches` iteratee shorthand.
let gfg = _.takeRightWhile(users, {
    'user':
        'pebbles', 'active': false
});

// Printing the output 
console.log(gfg);

Output:

[{user: 'pebbles', active: false}]

Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.



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