从数组中的值框中删除逗号

时间:2017-02-16 11:58:20

标签: node.js

Nodejs:如何删除数组

中value参数的逗号
[[ '000150607',42439,'F16','605661','CO.,LTD'][ '0001502607',424329,'Fg16','6095661','DCO.LTD'][ '00002607',4249,'16','60995661','DCO.,LTD']]

我想删除逗号形式CO。,LTD like =>有限公司 如何实现这一目标。

2 个答案:

答案 0 :(得分:0)

只需遍历子数组值并使用replace

var array = [
  ['000150607', 42439, 'F16', '605661', 'CO.,LTD'],
  ['0001502607', 424329, 'Fg16', '6095661', 'DCO.LTD'],
  ['00002607', 4249, '16', '60995661', 'DCO.,LTD']
];
console.log(array);
for (var i = 0; i < array.length; i++) {
  for (var j = 0; j < array[i].length; j++) {
    if (typeof array[i][j] === 'string') {
      array[i][j] = array[i][j].replace(',', '');
      console.log(array[i][j])
    }
  }
}
console.log(array);

答案 1 :(得分:0)

您可以使用JavaScript数组的.map()方法

let arr = [
    [ '000150607',42439,'F16','605661','CO.,LTD'],
    [ '0001502607',424329,'Fg16','6095661','DCO.LTD'],
    [ '00002607',4249,'16','60995661','DCO.,LTD']
];

var withoutComma = arr.map((singleArray) => {
    return singleArray.map((singleValue) => {
        return typeof singleValue === 'string' ? singleValue.replace(',', '') : singleValue;
    });
});

console.log(withoutComma);