如何使用JavaScript来代替逗号“,”在一个ArrayList'/' [英] How to replace comma ',' in an arraylist to ' / ' using javascript

查看:85
本文介绍了如何使用JavaScript来代替逗号“,”在一个ArrayList'/'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何用/在一个数组列表,使用JavaScript替代,。在这里,我的数组列表有两个字符串'以逗号分隔值,但我希望把它在一个单一的字符串通过分离值的形式/?

有关如:数组[] = {值1,A1 / A2 / A3} 由阵列取代[] = {值1 / A1 / A2 / A3}

例如:在这里,我要替换这是作为结果 [3101/102/103] [3/101/102 / 103]

任何人都可以请建议?


解决方案

  String.prototype.replaceAll =功能(目标,更换){
  返回this.split(目标)。加入(更换);
};
阵列=新的Array(A1 / A2 / A3)对于(i = 0; I< array.length ++我){
    数组[我] =阵列[I] .replaceAll(/,,)
}

这是否帮助?

How can I replace ',' with a '/' in an array list using javascript. Here my array-list has two string 'values separated by a comma ',' but I want to make it in form of a single string separating the values by '/' ?

For eg : array[] = { value1, a1/a2/a3} to be replaced by array[] = {value1/a1/a2/a3}

For example: Here I want to replace the outcome which comes as [3,101/102/103] by [3/101/102/103].

Can anyone please suggest ?

解决方案

String.prototype.replaceAll = function(target, replacement) {
  return this.split(target).join(replacement);
};
array = new Array("a1/a2/a3")

for (i = 0; i < array.length; ++i) {
    array[i] = array[i].replaceAll("/",",")
}

does this help?

这篇关于如何使用JavaScript来代替逗号“,”在一个ArrayList'/'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆