Search code examples
javascriptarraysstringprototypejs

Join array elements from second onward


I am building a csv, I need to skip the metadata from the array which is at 1st pos

How do I get a output like

"2","3","4" "6","7","8"

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction() {
    var list = [
      ["meta1", "2", "3", "4"],
      ["meta2", "6", "7", "8"]
    ];
    
    var csv = list.map(function(d) {
      return '"' + d.join('","') + '"';
    }).join('<br/>');
                    
    
    var x = document.getElementById("demo");
    x.innerHTML = csv;
}
</script>

</body>
</html>


Solution

  • You can call shift() which remove first element from array

    https://www.w3schools.com/jsref/jsref_shift.asp

    Or

    you can use splice().Usage is explained for example here:

    How to remove element from an array in JavaScript?