aaa 3333,bbb 5,ccc 10
First i need to split based on Comma and the i need to split based on space to make it key value pair... how do i do in JavaScript.
Use the split method:
var items = str.split(',');
for (var i = 0; i < items.length; i++) {
var keyvalue = items[i].split(' ');
var key = keyvalue[0];
var value = keyvalue[1];
// do something with each pair...
}
Use String.split() : https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/split
var theString = 'aaa 3333,bbb 5,ccc 10';
var parts = theString.split(',');
for (var i=0; i < parts .length; i++) {
var unit = parts.split(' ');
var key = unit[0];
var value = unit[1];
}