3

How to convert String into the array in React Native. for example:-

var myString = 'this, is my, string';

separate string with "," and output must be

  myArray = [this, is my, string];
  on myArray[0] value is "this",
  on myArray[1] value is " is my",
  on myArray[2] value is " string"
1
  • 2
    myString.split(',') Commented Sep 7, 2017 at 13:43

3 Answers 3

15

Simply use string.split() to split the string into an array using commas as delimiters.

var myArray = myString.split(',');
Sign up to request clarification or add additional context in comments.

2 Comments

No problem :) Glad I could help.
If you are satisfied, please mark it as the answer to you question ;)
6

var myString = 'this, is my, string';

console.log(myString.split(','));

Comments

2

here is my example

var oldString = 'this, is my, string';
var mynewarray=oldString.split(',')
console.log("My New Array Output is",mynewarray);

and output like that

My New Array Output is [ 'this', ' is my', ' string' ]

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.