Skip to main content

Archive

Show more

How to get the first element of an array using javascript

How-to-get-the-first-element-of-an-array-using-javascript


Question: How to get the first element of an array using javascript?

Answer:

Given array.

var myArray = [404, 301, 201, 122, 40, 20];

Get first element of array using index.

console.log(myArray[0]);

Get first element of array using function.

function arrayFirstElement(arrayReceive){
  return arrayReceive[0];
}

console.log(arrayFirstElement(myArray));

output:

404


We try to provide you the best content, if there is any mistake in this article or there is any mistake in code, then let us know.

Comments