[英]converting comma separated string to comma separated number
I am getting comma separated string as 2019,15,7
- from backend. 我正在从后端以逗号分隔的字符串作为2019,15,7
。 need to convert as comma separated numbers like 2019, 15, 7
is there a shorthand for this? 需要转换为以逗号分隔的数字,例如2019, 15, 7
这是否有简写形式?
any one help me with shortest approach? 有谁能以最短的方式帮助我?
Like @Martijn said, you use split and parseInt. 就像@Martijn所说的,您使用split和parseInt。
If you then need to use those numbers in a Date constructor you could do it like this 如果您随后需要在Date构造函数中使用这些数字,则可以这样做
const [y,d,m] = "2019,15,7".split(',').map(x => parseInt(x));
const myDate = new Date(y,m-1,d);
Bear in mind the month goes from 0 to 11 in the constructor. 请记住,在构造函数中,月份从0到11。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.