How to remove all element from array except the first one in javascript How to remove all element from array except the first one in javascript arrays arrays

How to remove all element from array except the first one in javascript


You can set the length property of the array.

var input = ['a','b','c','d','e','f'];  input.length = 1;console.log(input);