admin管理员组文章数量:1289635
I have an array which I need to remove the mas and "" surrounding each item in the array. I used .join('')
and also toString()
. This only gave me 0 1 2 3
.
What I have:
Array = ["0", "1", "2", "3"]
Need it to look like this:
Array = ["0 1 2 3"]
I have an array which I need to remove the mas and "" surrounding each item in the array. I used .join('')
and also toString()
. This only gave me 0 1 2 3
.
What I have:
Array = ["0", "1", "2", "3"]
Need it to look like this:
Array = ["0 1 2 3"]
Share
Improve this question
edited Jun 23, 2016 at 21:07
j08691
208k32 gold badges269 silver badges280 bronze badges
asked Jun 23, 2016 at 21:06
HeatherHeather
1354 silver badges16 bronze badges
15
- 1 Why do you want the array to contain a single string? If you want a single string, why bother with the array? – Quentin Commented Jun 23, 2016 at 21:07
- That result seems very strange – charlietfl Commented Jun 23, 2016 at 21:08
- So you want to turn an array of four strings into an array with a single space-separated string? – TheZanke Commented Jun 23, 2016 at 21:08
- Why do you need an array with a single string? – Praveen Kumar Purushothaman Commented Jun 23, 2016 at 21:08
- I need to pass this information to a 3rd party application. Basically, what I am doing is selecting multiple days for a schedule and passing the array with the days selected. It will only recognize the days if the array is as: array = ["0 1 2 3"] – Heather Commented Jun 23, 2016 at 21:10
2 Answers
Reset to default 8You can use join()
var ar = ["0", "1", "2", "3"];
console.log([ar.join(' ')])
var newArray = [oldArray.join(' ')];
Or alternatively
var newArray = oldArray.reduce(function(a, b) {
return a + " " + b;
});
本文标签: How to remove comma and quotquot from JavaScript ArrayStack Overflow
版权声明:本文标题:How to remove comma and "" from JavaScript Array? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741421225a2377816.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论