convert string into array of integers

后端 未结 11 1678
刺人心
刺人心 2020-11-30 19:32

I want to convert the following string \'14 2\' into an array of two integers. How can I do it ?

11条回答
  •  隐瞒了意图╮
    2020-11-30 20:03

    An alternative to Tushar Gupta answer would be :

    '14 2'.split(' ').map(x=>+x);
    
    // [14, 2]`
    

    In code golf you save 1 character. Here the "+" is "unary plus" operator, works like parseInt.

提交回复
热议问题