Lodash教程

Lodash iteratee method

语法

_.iteratee([func=_.identity])
Creates a function that invokes func with the arguments of the created function. If func is a property name, the created function returns the property value for a given element. If func is an array or object, the created function returns true for elements that contain the equivalent source properties, otherwise it returns false.

参数

[func=_.identity] (*) − The value to convert to a callback.

输出

(Function) − Returns the callback.

实例

var _ = require('lodash');
var users = [
   { 'user': 'Joe', 'age': 36, 'active': true },
   { 'user': 'Robert', 'age': 40, 'active': false }
];
 
var result = _.filter(users, _.iteratee({ 'user': 'Joe', 'active': true }));
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

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