convert string into array of integers

后端 未结 11 1675
刺人心
刺人心 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:05

    Just for fun I thought I'd throw a forEach(f()) solution in too.

    var a=[];
    "14 2".split(" ").forEach(function(e){a.push(parseInt(e,10))});
    
    // a = [14,2]
    

提交回复
热议问题