I have a sentence like below:
mySentence = "12,alex \n" +"22,zac \n" +"41,sara \n" +"33,mike \n"
and want to convert into an object like below:
{
"12":"alex",
"22":"zac",
"41":"sara",
"33":"mike"
}
any solution would be my appreciated
>Solution :
Try this
var mySentence = "12,alex \n" +"22,zac \n" +"41,sara \n" +"33,mike \n"
mySentence = Object.fromEntries(mySentence.trim().split(' \n').map(v => v.split(',')))
console.log(mySentence)