Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to copy all the elements of an array except the last one in javascript

// how to copy all the elements of an array except the last one in javascript
const initial = arr => arr.slice(0, -1);
console.log(initial([1, 2, 3])); // [1, 2]
 
PREVIOUS NEXT
Tagged: #copy #elements #array #javascript
ADD COMMENT
Topic
Name
3+3 =