-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.js
More file actions
45 lines (32 loc) · 858 Bytes
/
1.js
File metadata and controls
45 lines (32 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/** Compare two Object whether is same or not */
// define objects
const ronit = {
city : "banglore",
age : 25,
salary : "7.5LPA"
}
const rajat = {
city : "Raipur",
age : 32
}
const rajnish = {
city : "banglore",
age : 25
}
function compareObj(obj1, obj2){
// extract all keys from an object obj1
let obj1Keys = Object.keys(obj1) ;
// let result = obj1Keys.every((elm) => obj1[elm] == obj2[elm] && obj2.hasOwnProperty(elm))
let result = obj1Keys.every((elm) => {
console.log("value of obj1 : ",obj1[elm]);
console.log("value of obj2 : ",obj2[elm]);
console.log("hasOwnProperty in obj2 : ", obj2.hasOwnProperty(elm));
if(obj1[elm] == obj2[elm] && obj2.hasOwnProperty(elm)){
return true ;
}else{
return false ;
}
})
console.log(result)
}
compareObj(ronit, rajat)