Create a function that takes an array and returns the first element

function getFirstValue(arr) {
return [0]
getFirstValue([1, 2, 3])
}

i thaught something like this however Im wrong. can anyone help?

getFirstValue([1, 2, 3]) ➞ 1

getFirstValue([80, 5, 100]) ➞ 80

getFirstValue([-500, 0, 50]) ➞ -500

This one worked -

function getFirstValue(arr) {
let firstOne= arr[0]
return arr[0]
}

to my understanding this stores a variable called firstOne which is equals to the 1st element in an array. which returns in any array the 1st element. please can someone confirm.

1 Like

Hello @UnknownScript

the declaring of the variable firstOne is not needed here just use the return arr[0]

and have a nice day :slight_smile:

I tried it on Edabit and the check was accepted