最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to covert String into array in React Native - Stack Overflow

programmeradmin3浏览0评论

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
  • 2 myString.split(',') – Kristianmitk Commented Sep 7, 2017 at 13:43
Add a comment  | 

3 Answers 3

Reset to default 15

Simply 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' ]
发布评论

评论列表(0)

  1. 暂无评论