OneCompiler

[JavaScript] How to get last but one element from an array?

I want to read last but one element of an array into a variable, how can we do that in Javascript?

1 Answer

4 years ago by

arr[arr.length - 2] gives you the last but one element of an array

4 years ago by Meera