I have this array:
["Name: Bob, LastName: Smith, Age: 77","Name: John, LastName: Cabbage, Age: 34","Name: Regan, LastName: Gobsmolly, Age: 80"]
How would you split all the strings in the array into more arrays from the comma, so the result would end up like this:
[["Name: Bob", "LastName: Smith", "Age: 77"],["Name: John", "LastName: Cabbage", "Age: 34"],["Name: Regan", "LastName: Gobsmolly", "Age: 80"]]
I have already tried splitting the items in the array with a loop, with the aim of returning the Name value from every array:
function getEntryNames(nameSplit) {
var nameSplit;
for (var i = 0; i < nameSplit.length; i++) {
return nameSplit[i].split(',')[i];
}
}
document.write(getEntryNames(theArray))
The problem is, the function will only split the first item in the array, so I get this result:
Name: Bob
When I really want this result:
Name: Bob, Name: John, Name: Regan
So how do you split items in an array to more arrays?