Javascript Split String On Every Other Symbol
I have a string in the form of ':x1:y1:x2:y2x3:y3:...:' and the keys and values Xn and Yn are arbitrary values so i can't use the length of the strings i would like to split this
Solution 1:
Try this:
var obj = (function(str){
var result = {};
str.replace(/([^\:]+)\:([^\:]+)/g, function($0, $1, $2){
result[$1] = $2;
});
return result;
})('x1:y1:x2:y2:x3:y3');
Post a Comment for "Javascript Split String On Every Other Symbol"