使用.join方法将数组转换为没有逗号的字符串 [英] using .join method to convert array to string without commas
本文介绍了使用.join方法将数组转换为没有逗号的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
没有分隔符的数组join()方法
我正在使用 .join()
将我的数组转换为字符串,因此当用户在计算器中选择数字时,我可以在文本框中输出它,我不确定如何我可以删除也在列表中输出的逗号.有人可以建议如何实现这一目标,或者我应该采用其他方法吗?
I'm using .join()
to convert my array to a string so I can output it in a text box as the user selects numbers in a calculator, I'm not entirely sure how I can remove the commas that are also being output in the list however. Can someone advise how this can be achieved or if there is a different approach I should be using?
JS
$(document).ready(function() {
var total = 0;
var arr = [];
//Testing
$('#calculator').children('.num').on('click', function(e) {
var clickedNumber = $(this).data('id');
arr.push(clickedNumber);
console.log(arr.join());
e.preventDefault();
});
});
JS Fiddle http://jsfiddle.net/CVr25/
JS Fiddle http://jsfiddle.net/CVr25/
推荐答案
就是这样:
arr.join("")
这篇关于使用.join方法将数组转换为没有逗号的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文