Reputation: 503
I am getting an array of single string $scope.Obj= ["Talking Spanish,Spanish food,Spanish things,Football"];
The split should be by watching ,
I need to break it down = ["Talking Spanish","Spanish food","Spanish things","Football"];
How can I do it using javascript?
Upvotes: 0
Views: 60
Reputation: 1
The split()
method splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.
In the following example, split()
looks for spaces in a string and returns the first 3 splits that it finds.
var myString = 'Hello World. How are you doing?';
var splits = myString.split(' ', 3);
console.log(splits);
This script displays the following:
["Hello", "World.", "How"]
Upvotes: 0
Reputation: 112
str.split(separator, limit) The above is common syntax to split a array https://medium.freecodecamp.org/how-to-make-your-react-native-app-respond-gracefully-when-the-keyboard-pops-up-7442c1535580
Upvotes: 0
Reputation: 1578
You can split 0th index of $scope.Obj with , and reassign to $scope.Obj.
$scope={};
$scope.Obj= ["Talking Spanish,Spanish food,Spanish things,Football"];
$scope.Obj=$scope.Obj[0].split(",")
console.log($scope.Obj);
Upvotes: 0
Reputation: 37755
You can use split
let arr = ["Talking Spanish,Spanish food,Spanish things,Football"];
let op = arr[0].split(',')
console.log(op)
Upvotes: 2