-
js Check if two array objects are the same |
Beta Was this translation helpful? Give feedback.
Answered by
hixb
Jul 11, 2022
Replies: 2 comments
-
`let arr1 = [{id: 1, name: '嘿嘿', go: 'xi', child: {id: 55}, is: 2}, 'hh'] console.log(equalsObj(arr1, arr2)) /**
/**
/** |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
xiao-ice
-
终于找到一个无机器人无作弊的平台,澡发给你,来玩吧,信誉不错跟的
http://www.wo9mlk.cn
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`let arr1 = [{id: 1, name: '嘿嘿', go: 'xi', child: {id: 55}, is: 2}, 'hh']
let arr2 = [{id: 1, name: '嘿嘿', go: 'xi', child: {id: 55}, is: 2}, 'hh']
console.log(equalsObj(arr1, arr2))
console.log(equalsObj(JSON.stringify(arr1), JSON.stringify(arr2)))
/**
*/
function equalsObj(oldData, newData) {
// 类型为基本类型时, 如果相同, 则返回trues
if (oldData === newData) return true
if (isObject(oldData) && isObject(newData) && Object.keys(oldData).length === Object.keys(newData).length) {
// 类型为对象并且元素个数相同
// 遍历所有对象中所有属性, 判断元素是否相同
for (const key in oldData) {
if (oldData.hasOwnProperty(key)) {
if (!equalsObj(oldData[key], newDa…