how to check the last item in an array javascript code example
Example 1: js array last element get
.slice(-1)[0]
Example 2: how to check the last item in an array javascript
const colors = ['red', 'yellow', 'green', 'blue']
const lastItem = colors[colors.length - 1]
console.log(lastItem)
Example 3: how to find last element in array
int [] y={1,2,3,4,5};
int c=(n.length-1);