如何将String转换为React Native中的数组。 例如: -
var myString = 'this, is my, string';
用","
分隔字符串
和输出必须
myArray = [this, is my, string];
on myArray[0] value is "this",
on myArray[1] value is " is my",
on myArray[2] value is " string"
答案 0 :(得分:4)
只需使用string.split()
将字符串拆分为数组,并使用逗号作为分隔符。
var myArray = myString.split(',');
答案 1 :(得分:4)
var myString = 'this, is my, string';
console.log(myString.split(','));
答案 2 :(得分:1)
这是我的例子
var oldString = 'this, is my, string';
var mynewarray=oldString.split(',')
console.log("My New Array Output is",mynewarray);
并像这样输出
My New Array Output is [ 'this', ' is my', ' string' ]