0
Q:

join array javascript

const elements = ['Sun', 'Earth', 'Moon'];

console.log(elements.join());
// output: "Sun,Earth,Moon"

console.log(elements.join(''));
// output: "SunEarthMoon"

console.log(elements.join('-'));
// output: "Sun-Earth-Moon"
20
var array = ["Joe", "Kevin", "Peter"];
array.join(); // "Joe,Kevin,Peter"
array.join("-"); // "Joe-Kevin-Peter"
array.join(""); // "JoeKevinPeter"
array.join(". "); // "Joe. Kevin. Peter"
13
['h', 'e', 'y'].join('')
// hey
2
<html>
  <select multiple class="select-colors">
    <option>blue</option>
    <option>green</option>
  </select>
</html>  

<script>
  var myColorSelect = $(".select-colors").val().join();
  
 console.log(myColorSelect);
</script>  
1
const arr = ["apple", "banana", "orange"];
const joinedArray = arr.join("---");
console.log(joinedArray);
// apple---banana---orange
0

New to Communities?

Join the community