我想比较两个OBJ之间的区别,但忽略了一些键
我正在使用lodash比较从邮递员返回的两个对象,但我想忽略动态值(page_view
deletion.update_time )。我该怎么做?我已经尝试将属性名称传递到省略
中,但它行不通...我该如何解决此问题?谢谢。
var obj1 = {
name: "James",
age: 17,
page_view: "2",
creation: "13-03-2016",
deletion: {
"article_id": 4469568,
"update_time": 1226,
}
}
var obj2 = {
name: "James",
age: 17,
page_view: "62",
creation: "13-03-2016",
deletion: {
"article_id": 4469568,
"update_time": 12265,
}
}
var result = _.isEqual(
_.omit(obj1, ['page_view', 'update_time']),
_.omit(obj2, ['page_view', 'update_time'])
);
if (!result) {
pm.expect.fail("Pro and Sta are different")
}
I'm using Lodash to compare two objects returned from Postman but I want to ignore the dynamic values (page_view
and deletion.update_time
). How can I do this? I've tried passing in the property names into omit
but it's not working... how can I resolve this issue? Thank you.
var obj1 = {
name: "James",
age: 17,
page_view: "2",
creation: "13-03-2016",
deletion: {
"article_id": 4469568,
"update_time": 1226,
}
}
var obj2 = {
name: "James",
age: 17,
page_view: "62",
creation: "13-03-2016",
deletion: {
"article_id": 4469568,
"update_time": 12265,
}
}
var result = _.isEqual(
_.omit(obj1, ['page_view', 'update_time']),
_.omit(obj2, ['page_view', 'update_time'])
);
if (!result) {
pm.expect.fail("Pro and Sta are different")
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在子对象上指定此内容:
You need to specify this on the sub-object: