Reputation: 159
I would like to change a phrase string into an array of word string in angularjs. For example i would like to transform $scope.phrase='come back home'
to $scope.words=['come','back','home']
Can you please help
Upvotes: 0
Views: 789
Reputation: 6467
Use split string method:
$scope.words = $scope.phrase.split(' '); // Using space as param
Upvotes: 1
Reputation: 48367
You need to use split method.
Split
method splits a String object into an array of strings.
$scope.words=$scope.phrase.split(' ');
Here is a working solution.
Upvotes: 1