-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobject_compare.html
43 lines (43 loc) · 940 Bytes
/
object_compare.html
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
<!DOCTYPE html>
<html>
<head>
<title>Compare keys value of an Array of Objects</title>
</head>
<body>
<h2>Compare keys value of an Array of Objects</h2>
<script>
let objArr = [
{
keyOne: 1,
keyTwo: 0,
keyThree: 1
},
{
keyOne: 0,
keyTwo: 0,
keyThree: 1
},
{
keyOne: 1,
keyTwo: 0,
keyThree: 0
}
];
let valuesOfArr = [];
let objKeys = Object.keys(objArr[0]);
console.log(objKeys);
objKeys.forEach(elem=> {
let val = [];
objArr.forEach(ele => {
val.push(ele[elem]);
});
valuesOfArr.push(val);
});
console.log(valuesOfArr);
valuesOfArr.forEach(ele => {
let areAllEqual = ele.every( (val, i, arr) => val === arr[0] );
console.log(areAllEqual);
});
</script>
</body>
</html>