[Solved] Convert String in JavaScript to an Object


Try with split() used for split the string by delimiter \n and Array#forEach method used for iterate the Array after the split string

var a="\nStructure=xyz\nIds=123,456,678,235";
var one = a.trim().split('\n');
var res ={};
one.forEach(a=> res[a.split('=')[0]]=a.split('=')[1])
//one.forEach(function(a){ res[a.split('=')[0]]=a.split('=')[1]}) for IE or unsupported Arrow function
console.log(res)

1

solved Convert String in JavaScript to an Object