1const isEqual = (...objects) => objects.every(obj => JSON.stringify(obj) === JSON.stringify(objects[0]));
2
3// Examples
4isEqual({ foo: 'bar' }, { foo: 'bar' }); // true
5isEqual({ foo: 'bar' }, { bar: 'foo' }); // false
1function checkObjEqual(obj1,obj2){
2for(let key in obj1){
3 if(!(key in obj2 )) return false;
4 if(obj1[key]!==obj2[key])return false;
5}
6return true;
7}
8
9console.log(checkObjEqual({maroon:'#800000',purple :'#800080'},{purple :'#800080',maroon:'#800000'})) //true
1function isEquivalent(a, b) {
2 // Create arrays of property names
3 var aProps = Object.getOwnPropertyNames(a);
4 var bProps = Object.getOwnPropertyNames(b);
5
6 // If number of properties is different,
7 // objects are not equivalent
8 if (aProps.length != bProps.length) {
9 return false;
10 }
11
12 for (var i = 0; i < aProps.length; i++) {
13 var propName = aProps[i];
14
15 // If values of same property are not equal,
16 // objects are not equivalent
17 if (a[propName] !== b[propName]) {
18 return false;
19 }
20 }
21
22 // If we made it this far, objects
23 // are considered equivalent
24 return true;
25}
26
27// Outputs: true
28console.log(isEquivalent(bobaFett, jangoFett));
29
1var myString = "Item1";
2
3var jsObject =
4{
5 Item1:
6 {
7 "apples": "red",
8 "oranges": "orange",
9 },
10 Item2:
11 {
12 "bananas": "yellow",
13 "pears": "green"
14 }
15};
16
17var keys = Object.keys(jsObject); //get keys from object as an array
18
19keys.forEach(function(key) { //loop through keys array
20 console.log(key, key == myString)
21});