Last active
December 23, 2021 11:25
-
-
Save hotrungnhan/2390fc5fc406239eccdb25f40b5ca576 to your computer and use it in GitHub Desktop.
Map key,value from old object to new key,value object and log it into console.
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 | |
// obj { | |
// a:0, | |
// b:1 | |
// } | |
// output { | |
// a1:1, | |
// a2:2 | |
// } | |
console.log(JSON.stringify(Object.fromEntries(Object.entries("your object with key value").map(([key,value])=>{ | |
return [key+1,value+1] | |
})),null,2)) | |
// just code itself | |
Object.fromEntries(Object.entries("your object with key value").map(([key,value])=>{ | |
return [key+1,value+1] | |
})), | |
// function | |
// calback take 2 parameter and should return an array with length =2 . | |
function mapObject(obj,calback){ | |
Object.fromEntries(Object.entries(obj,map(([key,value])=>{ | |
return callback(key,value) | |
}))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment