Mayank Agarwal

Mayank Agarwal

307 Articles Published

Articles by Mayank Agarwal

Page 8 of 31

How to Remove Duplicate Elements from an Array in JavaScript?

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 2K+ Views

To remove duplicate elements from an array in JavaScript can be achieved using various approaches. We will be understanding six different approaches in this article, which can be used according to our requirement in various cases. In this article we are having a JavaScript array and our task is to remove duplicate elements from array in JavaScript. Original Array: ["apple", "banana", "apple", "orange", "banana", "grape"] ...

Read More

process.env() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 553 Views

The process.env property in Node.js provides access to environment variables. It returns an object containing all environment variables available to the current process, making it essential for configuration management in Node.js applications. Syntax process.env Note: process.env is a property, not a method, so it doesn't require parentheses. Parameters process.env is a read-only object that doesn't accept parameters. It automatically contains all environment variables from the system where the Node.js process is running. Example: Accessing All Environment Variables Create a file named env.js and run it using: node env.js ...

Read More

How to use JavaScript to replace a portion of string with another value?

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 968 Views

In this article, we are going to explore replacing a portion of a string with another value using JavaScript. We can replace string parts in multiple ways. Below are some common methods − replace() method split() and join() methods replaceAll() method Let's discuss the above methods in detail. Using replace() Method The replace() method is an inbuilt JavaScript method that replaces the first occurrence of a substring or regular expression pattern with a new value. The original string remains unchanged. Syntax ...

Read More

Reading a text file into an Array in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 6K+ Views

Reading text files into arrays is a common task in Node.js applications. The built-in fs module provides both synchronous and asynchronous methods to read files and convert their content into arrays by splitting lines. Using fs.readFileSync() (Synchronous) The synchronous approach blocks code execution until the file is completely read. This method is suitable for smaller files or when you need the data immediately. // Importing the fs module const fs = require("fs"); // Function to read file and convert to array const readFileLines = filename => fs.readFileSync(filename) .toString('UTF8') .split(''); ...

Read More

How to return all matching strings against a RegEx in JavaScript?

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 505 Views

In JavaScript, regular expressions (RegEx) are powerful tools for pattern matching in strings. While string.search() returns the position of the first match, there are multiple methods to return all matching strings or substrings against a RegEx pattern. Using string.search() Method The search() method returns the index of the first match, or -1 if no match is found. Syntax let index = string.search(expression) Parameters string − The string to be searched expression − The regular expression pattern to match Example ...

Read More

script.createCachedData() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 235 Views

The script.createCachedData() method in Node.js creates a code cache for VM scripts, improving performance when executing the same script multiple times. This method is part of the vm module and generates cached bytecode that can be reused. Syntax script.createCachedData() Parameters This method takes no parameters. It creates cached data from the current script instance and returns a Buffer containing the cached bytecode. Return Value Returns a Buffer object containing the cached bytecode that can be used with the cachedData option when creating new script instances. Example 1: Basic Cached Data Creation ...

Read More

send(), sendStatus() and json() method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 5K+ Views

In Express.js, the send(), sendStatus(), and json() methods are essential for sending responses to clients. The send() method sends data in string format, json() sends data in JSON format with proper headers, and sendStatus() sends HTTP status codes with default status messages. Prerequisites Node.js installed Basic understanding of Express.js Installation Install the Express module using npm: npm install express Understanding sendStatus() Method The sendStatus() method sends an HTTP status code along with its default message. Common status codes include 200 (OK), 404 (Not Found), 201 (Created), ...

Read More

How to search a string for a pattern in JavaScript?

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 784 Views

Searching strings for specific patterns is a common task in JavaScript. Strings are data types and are represented as a sequence of characters. Searching patterns means verifying the presence of a specific pattern in a given string. A pattern would be a specific word, specific characters, and so on. JavaScript offers several powerful methods for pattern matching, such as inbuilt string methods and regular expressions. This article will guide you on how to search strings for specific patterns in JavaScript. Table of contents Searching strings for specific patterns in JavaScript can be done in the following ways: ...

Read More

urlObject.auth() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 175 Views

The auth property of a parsed URL object contains the username and password portion of a URL, also known as userInfo. The username and password are separated by a colon (:). Syntax urlObject.auth Parameters The auth property is read-only and does not require any input parameters. It returns the authentication credentials from the parsed URL. Example 1: Basic Authentication Create a file named auth.js and run it using node auth.js: // Importing the URL module const url = require('url'); var adr = 'https://username=hello:password=tutorialspoint@www.tutorialspoint.com/'; // Parsing the above URL ...

Read More

How to set the cursor to wait in JavaScript?

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 3K+ Views

In this article, we are going to look at how to set the cursor to wait in JavaScript. The wait cursor provides visual feedback to users that a process is running and prevents them from accidentally triggering multiple actions. Setting the cursor to wait is essential for improving user experience during operations like form submissions, file uploads, or API calls. JavaScript allows us to dynamically control cursor appearance using the CSS cursor property. Common Use Cases Here are typical scenarios where the wait cursor is beneficial: Processing payments to prevent double submissions ...

Read More
Showing 71–80 of 307 articles
« Prev 1 6 7 8 9 10 31 Next »
Advertisements