Lodash教程

Lodash takeRightWhile method

语法:

_.takeRightWhile(array, [predicate=_.identity])
Creates a slice of array with elements taken from the end. Elements are taken until predicate returns falsey. The predicate is invoked with three arguments: (value, index, array).

参数

array (Array) − The array to query. [predicate=_.identity] (Function) − The function invoked per iteration.

输出:

(Array) − Returns the slice of array.

实例:

var _ = require('lodash');
var users = [
   { 'user': 'Mark',   'active': false },
   { 'user': 'Joe',     'active': true },
   { 'user': 'Jake', 'active': false }
];
 
var result = _.takeRightWhile(users, function(o) { return !o.active; });
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

命令:

\>node tester.js

输出:

[ { user: 'Jake', active: false } ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4