js数组拼接成字符串,去除最后一个逗号

  res.data.rules.forEach(function(item) {
            agtlValues += item.ruleNum + item.ruleValue + " \n";
            ruleIds += item.id + ",";
          });
          ruleIds = ruleIds.substring(0, ruleIds.lastIndexOf(","));

拼接"\n"可以换行展示

ruleIds+=item.id+",";是比较简洁的拼接;

substring(0,x);截取0到x的字符串;

lastIndexOf(",")最后一个逗号的下标;

posted @ 2020-06-04 14:47  看到我的div了吗?  阅读(3393)  评论(0编辑  收藏  举报