Created
October 3, 2024 21:33
-
-
Save naosim/f564878251f7e7b39e07e7da80e8625c to your computer and use it in GitHub Desktop.
fromEntries
This file contains 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
const text = "name=naosim,point=10,state=4" | |
const result = text.split(",").reduce((memo, v) => { | |
const [key, value] = v.split("="); | |
return {...memo, [key]:value}; | |
}, {}) | |
console.log(result); | |
const result2 = Object.fromEntries(text.split(",").map(v => v.split("="))) | |
console.log(result2); | |
/** | |
* 出力 | |
* { name: 'naosim', point: '10', state: '4' } | |
* { name: 'naosim', point: '10', state: '4' } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment