I have a string like this
var information = 'name:ozil,age:22,gender:male,location:123 street';
I want to make an array of key value object like this
var informationList=[
{
'key':'name',
'value':'ozil'
},
{
'key':'gender',
'value':'male'
},
{
'key':'location',
'value':'123 street'
},
]
split
function – bigbobr Nov 25 '14 at 11:46'name:ozil,age:22,gender:male,location:123 street'.split(',').map(function(el) { var p = el.split(':'); return {key: p[0], value: p[1]}; })
– dfsq Nov 25 '14 at 11:49