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); OR, Use splice(startIndex) method var input = [‘a’,’b’,’c’,’d’,’e’,’f’]; input.splice(1); console.log(input); OR use Array.slice method var input = [‘a’,’b’,’c’,’d’,’e’,’f’]; var output = input.slice(0, 1) // 0-startIndex, 1 – endIndex console.log(output);

Deleting array elements in JavaScript – delete vs splice

delete will delete the object property, but will not reindex the array or update its length. This makes it appears as if it is undefined: > myArray = [‘a’, ‘b’, ‘c’, ‘d’] [“a”, “b”, “c”, “d”] > delete myArray[0] true > myArray[0] undefined Note that it is not in fact set to the value undefined, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)