Created
March 27, 2021 18:44
-
-
Save andres-mora-vanegas/7f1cfa8d3663ccfc39e469b303541021 to your computer and use it in GitHub Desktop.
Function to compare two objects and return keys of first against second
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* example of use | |
const m ={uno:'1',dos:2,tres:'3',cuatro:'4',cinco:{uno:1,dos:2,tres:3}} | |
const n = {uno:true,dos:true,tres:true} | |
console.log(extract(m,n)) | |
// return {uno:'1',dos:2,tres:'3'} | |
*/ | |
function extract(original, newObj) { | |
const responseNewObj = {}; | |
Object.keys(original).forEach((e) => { | |
if (newObj[e] !== undefined) { | |
responseNewObj[e] = original[e]; | |
} | |
}); | |
return responseNewObj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment