Javascript Articles

Page 96 of 534

Can one string be repeated to form other in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 148 Views

We are required to write a JavaScript function that takes in two strings, str1 and str2, as the first and the second argument. Our function should return the minimum number of times we should repeat string str1 so that string str2 is a substring of it. If it is impossible for str2 to be a substring after repeating it, we should return -1. Problem Example For example, if the input to the function is: const str1 = 'wxyz'; const str2 = 'yzwxyzwx'; The expected output is 3, because by repeating str1 three times ...

Read More

crypto.createDiffieHellman(primeLength, [generator]) Method in Node.js

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

The crypto.createDiffieHellman(primeLength, [generator]) method creates a Diffie-Hellman key exchange object by generating a prime number of specified bit length. This is commonly used for secure key exchange between parties. Syntax crypto.createDiffieHellman(primeLength, [generator]) Parameters The parameters are described below: primeLength – The number of prime bits to generate. Must be a number. generator – Optional generator for creating the exchange key object. ...

Read More

crypto.randomBytes() Method in Node.js

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

The crypto.randomBytes() method generates cryptographically strong pseudo-random data in Node.js. This method ensures sufficient entropy before completion, typically taking only a few milliseconds to generate secure random bytes. Syntax crypto.randomBytes(size, [callback]) Parameters The parameters are described below: size – Specifies the number of bytes to generate. Must not exceed 2**31 - 1. callback – Optional callback function called if an error occurs. If omitted, the method runs synchronously. Asynchronous Example ...

Read More

crypto.getCurves() Method in Node.js

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

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

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

urlObject.auth() Method in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 167 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 add float numbers using JavaScript?

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

In JavaScript, floating-point numbers can be added directly using the addition operator (+). The parseFloat() function converts strings to floating-point numbers, but is not required when working with numeric literals. Example 1: Direct Addition The simplest way to add float numbers is using the addition operator directly: let inputFloat1 = 2.3; let inputFloat2 = 3.5; console.log("The two float values are:", inputFloat1, "and", inputFloat2); let result = inputFloat1 + inputFloat2; console.log("The sum of the float values is:", result); The two float values are: 2.3 and 3.5 The sum of the float values ...

Read More

Grouping array nested value while comparing 2 objects - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 454 Views

When working with complex nested objects, you often need to compare and group data from different states. This article demonstrates how to group array nested values while comparing two objects in JavaScript. Problem Statement Suppose we have a JSON object containing "before" and "after" states of device data: const input = { "before": { "device": [ { "id": "1234", "price": "10", ...

Read More

Sort array of objects by string property value - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 366 Views

Sorting an array of objects by a string property is a common task in JavaScript. The most efficient approach uses the built-in sort() method with localeCompare() for proper alphabetical ordering. Sample Data Let's work with this array of person objects: const people = [ { first_name: 'Lazslo', last_name: 'Jamf' }, { first_name: 'Pig', last_name: 'Bodine' }, { first_name: 'Pirate', last_name: 'Prentice' } ]; console.log("Original array:", people); Original array: [ { first_name: 'Lazslo', last_name: 'Jamf' }, { ...

Read More
Showing 951–960 of 5,340 articles
« Prev 1 94 95 96 97 98 534 Next »
Advertisements