如何在React Native中将字符串转换为数组

Bij*_*wat 0 javascript android ios react-native

在React Native中如何将String转换为数组 例如:-

var myString = 'this, is my, string';
Run Code Online (Sandbox Code Playgroud)

带有"," 和输出的单独字符串必须是

  myArray = [this, is my, string];
  on myArray[0] value is "this",
  on myArray[1] value is " is my",
  on myArray[2] value is " string"
Run Code Online (Sandbox Code Playgroud)

Lar*_*son 6

只需使用string.split()逗号作为分隔符,即可将字符串拆分为一个数组。

var myArray = myString.split(',');
Run Code Online (Sandbox Code Playgroud)


Ark*_*kej 5

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

console.log(myString.split(','));
Run Code Online (Sandbox Code Playgroud)