Skip to main content

Command Palette

Search for a command to run...

Return the First Element in an Array

Published
1 min read
Return the First Element in an Array
D

I am a Web Developer from Birtamode 1 Jhapa Nepal. As of 2022 i have 3 years of experience in CSS and 1 year of experience in Javascript + 6 Months of Experince in Node.js

Create a function that takes an array containing only numbers and return the first element.

Examples

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

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

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

Notes

The first element in an array always has an index of 0.

Javascript

function convert(a) {
    return  a[0];
}
let Array =[99,98,100];
console.log(convert(Array));

More from this blog

D

Dipesh Murmu

46 posts

A Full-Stack Laravel Developer with expertise in HTML, CSS, JavaScript, Tailwind, and core PHP. Leveraging the power of Laravel, I specialize in creating dynamic and responsive web applications.