javascript split string to array of int

后端 未结 5 1044
时光说笑
时光说笑 2020-12-09 07:33

I have a string that\'s on the page and from which I want an array of int.

2,3,0,43,23,53

I\'m writin

5条回答
  •  执念已碎
    2020-12-09 08:03

    var ArrayData = $.map($('#TheData').text().split(','), function(value){
        return parseInt(value, 10);
        // or return +value; which handles float values as well
    });
    

    You can use $.map to transform the array of strings to ints by calling parseInt on each of the elements in the array

提交回复
热议问题