NodeJs Tutorials
- NodeJs
- Install NodeJs
- Why use NodeJs
- NodeJs Process Model
- create First Application
- Run NodeJs Application
- Node.js Console
- Node.Js Modules
- URL Modules
- node.js Callback
- Node.js Events
- Upload Files
- Upload single & Multiple Files
- NodeJs File System
- NodeJs Email
- Debugging NodeJs
- .ENV
- NodeJs Mysql
- Helpers
- encription and decription in nodeJs
- Query string
- Date & Time
- Express Js
- Template Engine with Express
- MVC Pattern in Node.Js
- list of NPM Module
- Middleware
- Body Parser
- Render
- Nodemon module
- Morgan module
- Flash Message in ExpressJs
- Session
- Session store in database
- Cookies
- Helmet
- Multer
- Router: How To Use Routing In Node.Js
- App.Js
- express.json() and express.urlencoded()
- REST APIs in NodeJs
- Gloabal Objects
- Submit Form Data
- How to get Post Data in Node.js
- How to Get URL Parameters in Node.js
- How to create Node Project
- How to Insert Form Data Into the MySql Table Using Node.js
- How to fetch Data from MySQL database table using Node.js
- CRUD Example
- Await and Async
- Promises
- Login Example
- Password Encription
- How to validate Form (Form Validation) in Node.Js?
- Registration & Login form usingn Node.Js & MySql?
- Forgot & Reset Password
- File Upload in Node.Js with ExpressJs
- Resize Image Before Upload using Multer Sharp
- Upload multiple file using node.js with multer module
- Upload file using node.js with multer module
- Client IP Address
- REST API Downloading File in NodeJs
- Export and Download CSV From MySQL Database
- CRUD REST API
- CRUD REST API Example 2
- Enable HTTPS using Node
- How to send EMAIL using NodeJs?
- Dynamic dependent dropdown using NodeJs?
- Autocomplete Search
- Get and Send Data From Ajax Request
- Get and Post Data using Ajax
- Passport Authentication
- Node Js Data type
- Node Js Error
- Node Js Array Function
- Node Js String Function
- Puppeter Module
NodeJs Array
https://www.nodejsera.com/nodejs-tutorial-day6-array-methods.html
Foreach Loop Array in node JS
foreach loop alwayes use with array. Here you will learn how to usse foreach loop in node js.
const arr = ['PHP', 'codigniter', 'laravel', 'node', 'java','javascript'];
arr.forEach(element => {
console.log(element);
});
output :-
PHP
Codeigniter
Laravel
Node
java
javascript
Example2:-
const arr = ['PHP', 'codigniter', 'laravel', 'node', 'java','javascript'];
arr.forEach((element, index) => {
console.log('Key:' + index + ' Value:' + element);
});
Key:0 Value:PHP
Key:1 Value:codeigniter
Key:2 Value:laravel
Key:3 Value:node
Key:4 Value:java
Key:5 Value:javascript
Example 3
File Name :
Arrays are used to store multiple values in a single var . The array index starts from 0 to n-1.
How to create array in node js?
File Name :
var names = ["sana", "mahira", "mahtab","habib","sara"];
console.log(names);
//calculating the length of array
var len = names.length;
console.log(len);
//################## OR ##############
//Another way to create array
var arr = new Array(4); // declare an array "arr" of size 4
arr = [1,3,7,9]; // initialize elements of array
//################## OR ##############
// declare and initialize in a single statement
var arr1 = new Array(2,5,7);
console.log("arr : " + arr);
console.log("arr 1 : " + arr1);
push() function :-
push() is an array function of node.js that is used to add element to the end of an array.
array_name.push(element)
arr = ['s','a','n,'a'];
arr.push('m');
console.log(arr);
data_array = [4,5, 8,9, 10, 12];
data_array.push(15);
console.log(data_array);
push() with key value:-
key_val_arr = [
{id: 1, name: "sana" },
{id: 2, name: "mahtab" },
{id: 3, name: "mahira" }
];
key_val_arr.push({id: 4, name: "sara"});
console.log(key_val_arr);
pop() function in arrays
File Name :
File Name :