How to convert a string of numbers to an array of numbers?

前端 未结 15 2094
死守一世寂寞
死守一世寂寞 2020-11-27 10:29

I have below string -

var a = \"1,2,3,4\";

when I do -

var b = a.split(\',\');

I get b as

15条回答
  •  一向
    一向 (楼主)
    2020-11-27 11:06

    As a variant you can use combiantion _.map and _.ary methods from the lodash library. Whole transformation will be a more compact. Here is example from the official documentation:

    _.map(['6', '8', '10'], _.ary(parseInt, 1));
    // → [6, 8, 10]
    

提交回复
热议问题