How to covert String into array in React Native

20,510

Solution 1

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

var myArray = myString.split(',');

Solution 2

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

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

Solution 3

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' ]
Share:
20,510
Bijender Singh Shekhawat
Author by

Bijender Singh Shekhawat

I am from jaipur and i am ios developer. phone no. +918233285587

Updated on April 16, 2020

Comments

  • Bijender Singh Shekhawat
    Bijender Singh Shekhawat about 4 years

    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"