Convert strings in an array to numbers or convert numbers to strings

Convert strings in an array to numbers or convert numbers to strings

Scenario
Example: For the '1,2,3' returned by the following interface, the front end needs to be converted into an array.
Each value in the processed array becomes a string, and what I want is [1,2,3]
So I found the following method, which is very convenient to use

insert image description here

1. The method of converting strings in an array to numbers

['1', '2', '3'].map(Number)

insert image description here
2. Convert the numbers into strings in the array

[1, 2, 3].map(String) 

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/qq_44854653/article/details/126289834