join array javascript by / code example

Example 1: javascript join array

var array = ["Joe", "Kevin", "Peter"];
array.join(); // "Joe,Kevin,Peter"
array.join("-"); // "Joe-Kevin-Peter"
array.join(""); // "JoeKevinPeter"
array.join(". "); // "Joe. Kevin. Peter"

Example 2: js join

const elements = ['Fire', 'Air', 'Water'];

console.log(elements.join());
// expected output: "Fire,Air,Water"

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

console.log(elements.join('-'));
// expected output: "Fire-Air-Water"

Example 3: join array javascript

<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>

Tags:

Html Example