Home > OS >  How to return the first array element in the function?
How to return the first array element in the function?

Time:09-13

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

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

CodePudding user response:

for example

function getFirstValue($array){
    return $array[0];
}

CodePudding user response:

What language are you working in? The syntax will change slightly depending on the specific language, but most of the popular languages allow you to access elements in a list/array like this: aList[0] where 0 indicates the first element of the list. If you are working in python, for example, the function definition would look like this

def getFirstValue(aList):
    return aList[0]
  • Related