84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
For example, I have a string type like this
let str="[北京,重庆,天津]"
How can I convert it to an array type?
If it’s standardJSON, just useJSON.parse.For non-standard ones, it depends on the specific situation. For your example:
JSON
JSON.parse
const str="[北京,重庆,天津]"; const ans = str.slice(1, -1).split(',');
Correct answer upstairs, it is very convenient to convert strings and arrays into each other in js.
'1,2,3'.split(',') --> ['1','2','3'] ['1','2','3'].join(',') ----> '1,2,3'
If it’s standard
JSON
, just useJSON.parse
.For non-standard ones, it depends on the specific situation. For your example:
Correct answer upstairs, it is very convenient to convert strings and arrays into each other in js.