1

我有一个字符串数字数组,如下所示:“123,556”,“552,255,242”,“2,601”,“242”,“2”,“4”,我想将它们转换为 int 数字,但数字带有“ , 我想先从“123,556”转换为“123556”。我该怎么做?

4

6 回答 6

1
var numbersArray = ["153,32","32,453,23","45,21"];
for (var i = 0; i < numbersArray.length; i++) {
    numbersArray[i] = parseInt(numbersArray[i].replace(',',''));
}
于 2012-08-02T09:13:53.183 回答
1
var str = "552,255,242";
var numbr = parseInt(str.replace(/\,/g,''), 10);
于 2012-08-02T09:14:34.567 回答
0

只需使用split, join(或replace) 删除,andparseInt之后:

var number = "123,456";
number = number.split(',').join('');
number = parseInt(number, 10);
于 2012-08-02T09:13:09.640 回答
0

你可以使用.replace方法。

"123,556".replace(/,/g, '');
于 2012-08-02T09:13:28.627 回答
0

试试这个:string.replace(',', '');

于 2012-08-02T09:14:08.520 回答
0

就像是

var parseMe(myarray) {
  var out = new Array(myarray.length);
  for (i=0;i<myarray.length;i++){
      var tokens[] = myarray[i].split(",");
      var s = tokens[0] + tokens[1];
      out.push(parseInt(s));
  }
  return out;
}
于 2012-08-02T09:15:43.973 回答