Lodash教程

Lodash matchesProperty method

语法

_.matchesProperty(source)
Creates a function that performs a partial deep comparison between the value at path of a given object to srcValue, returning true if the object value is equivalent, else false.

参数

path (Array|string) − The path of the property to get. srcValue (*) − The value to match.

输出

(Function) − Returns the new spec function.

实例

var _ = require('lodash');
var objects = [
   { 'a': 1, 'b': 2, 'c': 3 },
   { 'a': 4, 'b': 5, 'c': 6 }
];
 
var result = _.find(objects, _.matchesProperty('a', 4));
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

{ a: 4, b: 5, c: 6 }
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4