Quantcast
Channel: Envato Tuts+ Code
Viewing all articles
Browse latest Browse all 5166

Node.js Succinctly: Arrays

$
0
0

Node.js provides an Array object for collection manipulation. In general, a Node.js Array object has the same behavior as a JavaScript Array object. In this section, we are going to manipulate an Array object in Node.js 

Creating an Array Object

There are three ways to create an Array object. The first is simply by typing the array object.

Option two is to create an Array object by instantiating the Array object. 

The last option is to create an Array object by inserting collection data. 

Inserting Data

After creating an Array object, we can insert data. Use [] with the index if you want to assign the value. 

You can also use the push() function to insert data. 

Accessing Data

To access array data, you can use [] with the data index parameter. 

Showing array data

Updating Data

To update an item of array data, you can use [] with the data index and thus assign a new value. 

Removing Data

You can use the pop() function to remove data from the Array. If you want to remove data by specific index then you can use the splice() function.

The following is a sample script for removing data: 

This tutorial represents a chapter from Node.js Succinctly, a free eBook from the team at Syncfusion.


Viewing all articles
Browse latest Browse all 5166

Trending Articles