How to Get First Element of Array in Node JS?
Jul 22, 2022
Hello Friends,
Now, let's see an example of the get First Element of Array in Node Js Example. you will learn Node.js to get the first element of the array. I explained simply how to get the first element of an array in node.js?. We will look at the example of get the first item in the array in Node Js. follow bellow step for array get the first element get using Node Js.
In this example, I will create a simple array with the days with the name. Then I will get the first element of the array using shift() function and 0 key.
let's see below a simple example with output:
Example: 1
index.js
myArray = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
# Get First Element
firstElem = myArray[0];
console.log(firstElem);
Output:
Sun
Example: 2
index.js
myArray = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
# Get First Element
firstElem = myArray.shift();
console.log(firstElem);
Output:
Sun
- How to Install Node Js and NPM Ubuntu?
- How to used Google ReCaptcha V3 in Node Js Express?
- How to Send Email with Attachment in Node js?
- How to Insert Data from Form into MySQL Database using Node js Express?
- Install Node Js and NPM Ubuntu 18.04/20.04/22.04 Tutorial
- How to Delete Data by id into MongoDB in Node JS?
- Install Node.js 16/17/18 on CentOS 8 Tutorial
- How to Upload File in MongoDB using Node js Express?