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
  • 47,092
  • 13
  • 101
  • 128
1

Use split string method:

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

leo.fcx
  • 6,137
  • 2
  • 21
  • 37