主题
isMatch
js
_.isMatch(object, source)
在 object
和 source
之间执行部分深度比较以确定 object
是否包含相等的属性值。
¥Performs a partial deep comparison between object
and source
to determine if object
contains equivalent property values.
注意:当部分应用 source
时,此方法相当于 _.matches
。
¥Note: This method is equivalent to _.matches
when source
is partially applied.
部分比较将分别将空数组和空对象 source
值与任何数组或对象值进行匹配。有关支持的值比较的列表,请参阅 _.isEqual
。
¥Partial comparisons will match empty array and empty object source
values against any array or object value, respectively. See _.isEqual
for a list of supported value comparisons.
新增于
¥Since
3.0.0
参数
¥Arguments
object
(对象):要反转的对象。¥
object
(Object): The object to inspect.source
(对象):要匹配的属性值的对象。¥
source
(Object): The object of property values to match.
返回
¥Returns
(布尔):如果 object
是匹配,则返回 true
,否则返回 false
。
¥(boolean): Returns true
if object
is a match, else false
.
示例
¥Example
js
var object = { 'a': 1, 'b': 2 };
_.isMatch(object, { 'b': 2 });
// => true
_.isMatch(object, { 'b': 1 });
// => false