0

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?

4 Answers 4

2

You can use split

let arr = ["Talking Spanish,Spanish food,Spanish things,Football"];

let op = arr[0].split(',')

console.log(op)

Sign up to request clarification or add additional context in comments.

Comments

0

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);

Comments

0

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

Comments

0

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"]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.