how can covert key=value pair string json object
input :
test = 1 testtwo = 2
output should json object
"test":"one","testtwo":"two"
is input
string? first split \n
array of key/value-pairs, , split each pair =
, array of key , value.
var input = `test = 1 testtwo = 2 testthree = 3 testfour = four`; var output = input.split('\n').reduce(function(o,pair) { pair = pair.split(' = '); return o[pair[0]] = pair[1], o; }, {}); console.log(output);
Comments
Post a Comment