Lodash教程

Lodash dropRightWhile method

语法:

_.dropRightWhile(array, [predicate=_.identity])
Creates a slice of array excluding elements dropped from the end. Elements are dropped 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: 'Sam', active: false },
   { user: 'Ted', active: true },
   { user: 'Julie', active: false }
];
var result = _.dropRightWhile(users, function(user) { return !user.active; });
console.log(result);
result = _.dropRightWhile(users, ['active', false]);
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

命令:

\>node tester.js

输出:

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