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
 |  Show 10 more ments

2 Answers 2

Reset to default 8

You 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