I have a rather specific problem.
I'm using ng-csv, and because it doesn't support nested arrays, I'm turning an array into a string.
Something like this:
[
{"name":"Maria","chosen":false},
{"name":"Jenny","chosen":false},
{"name":"Ben","chosen":false},
{"name":"Morris","chosen":false}
]
Turns into:
$scope.var = "Maria, Jenny, Ben, Morris"
My problem is that when I was using the array I was able to count the number of names in the array (which I need for UI reasons), but with the string it gets tricky.
Basically, I cannot count the number of words because some names might include last name, but I thought I could count commas, and then add 1.
Any pointers on how to do just that?
commas = str.length - str.replace(/,/g, "").length;
– Alex K. Dec 22 '14 at 18:41