0

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

2 Answers2

1

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.

Mihai Alexandru-Ionut
  • 44,345
  • 11
  • 88
  • 115
1

Use split string method:

$scope.words = $scope.phrase.split(' '); // Using space as param

leo.fcx
  • 5,799
  • 2
  • 18
  • 36