Functions - return last elements

PHOTO EMBED

Wed May 04 2022 09:27:29 GMT+0000 (Coordinated Universal Time)

Saved by @Luduwanda #javascriptreact

// DEFINE YOUR FUNCTION BELOW:
function lastElement(arr){
    if (arr.length === 0 ){
    return null
      
             //to get the wanted arr's index number
}else return arr[arr.length-1]
}

lastElement([3,5,7])
lastElement([1])
lastElement([0])
content_copyCOPY