Rua*_*rte 2 javascript lodash react-hooks
useEffect我的reactJS中有以下代码
const A1 = [{id: 1, nome: "Ruan"}, {id: 2, nome: "Gleison"}]\nconst A2 = [{id: 2, nome: "Gleison"}, {id: 3, nome: "Geraldo"}]\n\nconst results = _.xor(A1,\xc2\xa0A2);\n\nconsole.log(results)\nRun Code Online (Sandbox Code Playgroud)\nlodashis的逻辑_.xor是返回两个数组之间的差异,但是,事实并非如此
我得到的回报如下
\n0: Object {id: 1, nome: "Ruan"}\n1: Object {id: 2, nome: "Gleison"}\n2: Object {id: 2, nome: "Gleison"}\n3: Object {id: 3, nome: "Geraldo"}\nRun Code Online (Sandbox Code Playgroud)\n我感谢所有提供帮助的努力
\n您可以使用xorBy来指示用于比较的属性:
const A1 = [{id: 1, nome: "Ruan"}, {id: 2, nome: "Gleison"}]
const A2 = [{id: 2, nome: "Gleison"}, {id: 3, nome: "Geraldo"}]
const results = _.xorBy(A1, A2, 'id'); // or 'nome'
console.log(results)Run Code Online (Sandbox Code Playgroud)
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js"></script>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3010 次 |
| 最近记录: |