I\'ve been losing hours over something that might be trivial:
I\'ve got a list of comma-separated e-mail addresses that I want to convert to a specific JSON format,
How about:
var to = 'bigbadwolf@grannysplace.com,hungry@hippos.com,youtalkin@to.me',
obj = [],
parts = to.split(",");
for (var i = 0; i < parts.length; i++) {
obj.push({email:parts[i]});
}
//Logging
for (var i = 0; i < obj.length; i++) {
console.log(obj[i]);
}
Output:
Object {email: "bigbadwolf@grannysplace.com"}
Object {email: "hungry@hippos.com"}
Object {email: "youtalkin@to.me"}
Demo: http://jsfiddle.net/tymeJV/yKPDc/1/