Check if the literal object is included in another object with a built-in API

I mean, Object-B is included in Object-A when all the attributes of Object-B are included in object-A, and its values ​​are the same in object-A.

var obj_b={a:1,d:3} var obj_a={a:1,b:22,c:33,d:3} //--> obj_b includes in obj_a var obj_c={a:1,f:4}; isIncluded=(small,big)=>Object.keys(small).every((k)=>big[k] === small[k]) console.log( 'Does "obj-b" included in "obj-a" ? ',isIncluded(obj_b,obj_a) ) console.log( 'Does "obj-c" included in "obj-a" ? ',isIncluded(obj_c,obj_a) ) 

My question is:

Does ES6 / ES7 have the built-in API more elegant and shorter for this ?

For example, to extend an object from a source, did ES6 bring Object.assign(o1,o2) ?

Is there something like Object.isInclude(o1,o2) ?

+7
javascript object ecmascript-6
source share
1 answer

No no. Your decision is already short and elegant, although you can play golf for 4 more characters.

 const isSubObject = (small,big)=>Object.keys(small).every(k=>big[k]===small[k]); 
+2
source share

All Articles