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(",")最后一个逗号的下标;
标签:substring,lastIndexOf,js,逗号,item,拼接,ruleIds,id 来源: https://www.cnblogs.com/web-shu/p/13043519.html