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"
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"
Share
Improve this question
asked Sep 7, 2017 at 13:41
Bijender Singh ShekhawatBijender Singh Shekhawat
4,4942 gold badges32 silver badges37 bronze badges
1
|
3 Answers
Reset to default 15Simply use string.split()
to split the string into an array using commas as delimiters.
var myArray = myString.split(',');
var myString = 'this, is my, string';
console.log(myString.split(','));
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' ]
myString.split(',')
– Kristianmitk Commented Sep 7, 2017 at 13:43