gpt4 book ai didi

javascript - lodash:比较两个对象

转载 作者:行者123 更新时间:2023-11-30 15:59:21 27 4
gpt4 key购买 nike

我想通过 lodash 做这个:

first = { one: 1, two: 2, three: 3 }

second = { three: 3, one: 1 }

_.CustomisEqual(first, second);
// → true

third = { one: 1, two: 2, three: 3 }

fourth = { three: 4, one: 1 }

_.CustomisEqual(third, fourth);
// → false

但是通常的_.isEqual不支持这种比较方式,有没有办法通过lodash进行这种比较?

最佳答案

function CustomisEqual(objOne, objTwo) {
return !!_([objOne]).filter(objTwo).size();
}

first = { one: 1, two: 2, three: 3 }
second = { three: 3, one: 1 }

var resOne = CustomisEqual(first, second);

console.log('resOne ', resOne);
// → true

third = { one: 1, two: 2, three: 3 }
fourth = { three: 4, one: 1 }

var resTwo = CustomisEqual(third, fourth);

console.log('resTwo ', resTwo);
// → false
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.13.1/lodash.js"></script>

关于javascript - lodash:比较两个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38002537/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com