Skip to main content
๐Ÿ› Bug HuntJS JavaScript Easy+10 XP

Off-by-One Error

This function should return the last element of an array, but it has a bug.

๐Ÿ› Find the bug
1function lastElement(arr) {
2 return arr[arr.length];
3}
๐Ÿ› The bug is on line 2

๐Ÿ”ง Select the correct fix:

Priygop - Leading Professional Development Platform | Expert Courses & Interview Prep