Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

splitting an array with one element into an array with many elements

I want to take this array containing one item (a STRING with a bunch of comma delimited items)

["Bucknell Venture Plan Competition, Mitch Blumenfeld, DreamIt Ventures, Deep Fork Capital, John Ason, Mitchell Blumenfeld, Gianni Martire"]

I want to turn it into this. An array containing each name as a seperate array item.

["Bucknell Venture Plan Competition", "Mitch Blumenfeld", "DreamIt Ventures", "Deep Fork Capital", "John Ason", "Mitchell Blumenfeld", "Gianni Martire"]

Thanks!

UPDATE:

Thanks for the help. That worked!

like image 333
Nic Meiring Avatar asked May 11 '12 15:05

Nic Meiring


2 Answers

Simple as:

var myArr = ["Bucknell Venture Plan Competition, Mitch Blumenfeld, DreamIt Ventures, Deep Fork Capital, John Ason, Mitchell Blumenfeld, Gianni Martire"];
var myNewArr = myArr[0].split(",");
like image 114
Gabe Avatar answered Nov 07 '22 13:11

Gabe


I think this should work:

var items = ["Bucknell Venture Plan Competition, Mitch Blumenfeld, DreamIt Ventures, Deep Fork Capital, John Ason, Mitchell Blumenfeld, Gianni Martire"];
var array = items[0].split(",");
like image 33
Tower Avatar answered Nov 07 '22 12:11

Tower