Front End Technology Articles

Page 216 of 652

Filter array of objects whose properties contains a value in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

Filtering an array of objects based on property values is a common task in JavaScript. This technique allows you to search through all properties of objects to find matches based on a keyword. Sample Data Let's start with an array of objects containing user information: const arr = [{ name: 'Paul', country: 'Canada', }, { name: 'Lea', country: 'Italy', }, { name: 'John', country: 'Italy', }]; The Problem We need to filter objects where any ...

Read More

crypto.getCurves() Method in Node.js

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

The crypto.getCurves() method returns an array containing names of all supported elliptic curves in Node.js. These curves are used for creating Elliptic Curve Diffie-Hellman (ECDH) key exchange objects for secure cryptographic operations. Syntax crypto.getCurves() Parameters This method takes no parameters since it returns a complete list of all available elliptic curves. Return Value Returns an array of strings, where each string represents the name of a supported elliptic curve. Example Here's how to use crypto.getCurves() to retrieve all available elliptic curves: // Importing the crypto module const crypto ...

Read More

Check if user inputted string is in the array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 537 Views

We need to write a JavaScript program that checks if a user-inputted string exists in a predefined array. The program should return true if the string is found, false otherwise. This is commonly needed when validating user input against a list of acceptable values, such as checking usernames, categories, or allowed options. Using Array.includes() Method The includes() method is the most straightforward way to check if an array contains a specific value. It returns a boolean result. Check ...

Read More

process.argv() Method in Node.js

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

The process.argv property returns an array containing command-line arguments passed when the Node.js process was launched. The first element is the path to the Node.js executable, and the second is the path to the JavaScript file being executed. Syntax process.argv Parameters process.argv is a property, not a method, so it doesn't take any parameters. It automatically captures all command-line arguments passed to the Node.js process. Basic Usage Example Create a file named argv.js and run it using the command node argv.js: // Node.js program to demonstrate the use of process.argv ...

Read More

Count by unique key in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 705 Views

When working with arrays of objects, you often need to count occurrences based on unique key values. This is particularly useful for data analysis, grouping records, or creating summary statistics. The Problem Given an array of objects with nested properties, we want to count how many times each unique user appears: const arr = [ { assigned_user: { name: 'Paul', ...

Read More

process.chdir() Method in Node.js

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

The process.chdir() method changes the current working directory of the Node.js process. It throws an exception if the operation fails (such as when the specified directory doesn't exist) but returns no value on success. Syntax process.chdir(directory) Parameters directory – A string containing the path to the directory you want to change to. Return Value This method returns undefined on success and throws an error if the directory change fails. Example 1: Successful Directory Change // Node.js program to demonstrate process.chdir() const process = ...

Read More

Merge arrays in column wise to another array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 752 Views

When working with multiple arrays, you often need to combine their elements column-wise to create structured data. This technique merges arrays by their corresponding indices to form an array of objects. Problem Statement Suppose we have three arrays of numbers like these: const code = [123, 456, 789]; const year = [2013, 2014, 2015]; const period = [3, 4, 5]; We need to merge these arrays column-wise to create an array of objects where each object contains the corresponding elements from all three arrays: const output = [ ...

Read More

urlObject.auth() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 179 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

Take in array of objects and convert the above JSON to a Tree-structure in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 2K+ Views

In web development, you often need to convert flat arrays of hierarchical data into tree structures. This is common when working with organizational charts, file systems, or nested menus. Input Data Structure Suppose we have an array of objects representing parent-child relationships: const arr = [ { "parentIndex": '0', "childIndex": '3', "parent": "ROOT", "child": "root3" }, ...

Read More

How to process JavaScript nested array and display the order of numbers according to the level upto which they are nested?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 329 Views

Processing nested arrays and displaying elements with proper indentation based on their nesting level is a common JavaScript task. This technique helps visualize the hierarchical structure of nested data. Problem Statement Given a nested array like this: const arr = [23, 6, [2, [6, 2, 1, 2], 2], 5, 2]; We need to display numbers with indentation showing their nesting level. Elements at deeper levels should have more indentation. Expected Output 23 6 2 6 2 ...

Read More
Showing 2151–2160 of 6,519 articles
« Prev 1 214 215 216 217 218 652 Next »
Advertisements