How do I print elements of an array separated by commas in JavaScript?

Asked 2 years ago, Updated 2 years ago, 48 views

I want to print elements of the array separated by commas in JavaScript How shall I do it?

javascript jquery

2022-09-22 22:08

1 Answers

Try using Array.prototype.join().

var arr = new Array(3);
arr[0] = "Zero";
arr[1] = "One";
arr[2] = "Two";

document.write(arr.join(", "));

Like this.


2022-09-22 22:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.