array to list javascript code example
Example 1: javascript array to comma separated string
var colors = ["red", "blue", "green"];
var colorsCSV = colors.join(",");
Example 2: javascript array to csv string
var colors = ["red", "blue", "green"];
var colorsString = colors.join(",");
Example 3: javascript array
var colors = ["red","blue","green"];
for (var i = 0; i < colors.length; i++) {
console.log(colors[i]);
}
Example 4: javascript join address to string
var address = "foo";
var city;
var state = "bar";
var zip;
text = [address, city, state, zip].filter(Boolean).join(", ");
console.log(text)
Example 5: js get elements in array from x to y
arr.slice([início[,fim]])