最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

arrays - Removing quotes from console log in JavaScript - Stack Overflow

programmeradmin3浏览0评论

I'm trying to remove the printed single quotations which occur while running the following code.

I've tried playing around with the replace(/['"]+/g, ''but I'm not getting this correctly.

var arr = ["Alpha", "Omega", "Delta"];
var symbol = "weee";
for(x=0; x<arr.length; x++){
    console.log(x,symbol,arr[x]);
}

This returns:

0 'weee' 'Alpha'

1 'weee' 'Omega'

2 'weee' 'Delta' 

I'm trying to remove the printed single quotations which occur while running the following code.

I've tried playing around with the replace(/['"]+/g, ''but I'm not getting this correctly.

var arr = ["Alpha", "Omega", "Delta"];
var symbol = "weee";
for(x=0; x<arr.length; x++){
    console.log(x,symbol,arr[x]);
}

This returns:

0 'weee' 'Alpha'

1 'weee' 'Omega'

2 'weee' 'Delta' 
Share Improve this question edited Mar 15, 2017 at 2:38 aircraft 27k29 gold badges101 silver badges174 bronze badges asked Mar 15, 2017 at 2:33 dpxdpx 1172 silver badges10 bronze badges 1
  • don't use chrome, it's the only console that does that (well, not quite ... my console uses double quotes in the output) ... anyway ... who cares how strings a shown in a debugging tool - it makes no difference to the code – Jaromanda X Commented Mar 15, 2017 at 2:49
Add a ment  | 

1 Answer 1

Reset to default 7

If the types of console.log parameters are different, string type will be marked by quotation marks, so you can make the parameters to a single string, just like:

 console.log(x + ' ' + symbol + ' ' +arr[x]);
发布评论

评论列表(0)

  1. 暂无评论