Nikhilesh Aleti

Nikhilesh Aleti

69 Articles Published

Articles by Nikhilesh Aleti

Page 4 of 7

Match specific word in regex in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 11K+ Views

In JavaScript, matching specific words using regex (regular expressions) is a common task for string pattern matching. This article covers the main methods to match words: test(), match(), and matchAll(). Understanding Word Boundaries The \b assertion represents a word boundary, ensuring you match complete words rather than partial matches within other words. Word Boundary Example const sentence = "mickey is holding mic."; const regex = /\bmic\b/; ...

Read More

Return the sum of two consecutive elements from the original array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 2K+ Views

An Array is known as collection of similar data elements which are stored at contiguous memory locations. Array is such a simple data structure where we can access each data element in the array with the help index numbers, which starts from 0. The following is the basic declaration of array in JavaScript − const mobiles = ["SAMSUNG", "ONEPLUS", "APPLE"]; Sum of Two Consecutive Elements of an Array We are required to write a JavaScript function that takes in an array of Numbers and returns a new array with elements as sum of two ...

Read More

Splitting an array into chunks in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

In JavaScript, splitting an array into smaller chunks of equal size is a common operation. This article covers multiple approaches to divide array elements into n-sized chunks effectively. Input and Output Example: Consider an array with elements [10, 20, 30, 40] and chunk size of 2: Input = [10, 20, 30, 40] Output = [[10, 20], [30, 40]] The array gets divided into chunks where each sub-array contains the specified number of elements. Using slice() Method with for Loop The slice() method creates a shallow copy of a portion of an array ...

Read More

Finding the mid of an array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

Finding the middle element of an array is a common programming task in JavaScript. The approach differs depending on whether the array has an odd or even number of elements. Array Basics An Array in JavaScript is a data structure used to store multiple elements. These elements are stored at contiguous memory locations and accessed using index numbers starting from 0. Syntax const array_name = [item1, item2, ...]; Example of array declaration: const body = ['Eyes', 'Nose', 'Lips', 'Ears']; Understanding Middle Element Logic Finding the middle element depends ...

Read More

Finding product of Number digits in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 2K+ Views

We are required to write a JavaScript program that takes in a number and finds the product of all of its digits. Input Output Scenarios Here are examples of finding the product of number digits: Input = 12345 Output = 120 (1 × 2 × 3 × 4 × 5 = 120) We can also work with string numbers and convert them to integers: Input = "12345" Output = 120 Using Math.floor() and Modulo Operator The Math.floor() function returns the largest integer less than or equal to a given ...

Read More

Picking the largest elements from multidimensional array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

Given a multidimensional array, we need to pick the largest elements from each subarray in JavaScript. The multidimensional arrays are arrays inside an array. Whenever there are arrays inside the array, it works as a multidimensional array. Following is a one-dimensional array: const arr = ["Welcome", "to", "tutorials", "point"]; const numbers = [1, 5, 12, 67, 99]; This is how a multidimensional array looks like: const array = [["Mike tyson", "Vijay"], ["ananya", "charmee"], ["Lion", "Tiger"]]; This is how we can access elements from a multidimensional array: ...

Read More

Filter array based on another array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 14K+ Views

In this article, we are going to learn how to filter an array based on another array in JavaScript. An Array in JavaScript is used to store different elements. These elements are stored at contiguous memory locations. By using index numbers, we can access any or each data element present in the array. Index numbers start from 0. Syntax Following is the syntax of the array in JavaScript – const array_name = [item1, item2, ...]; The following is a simple declaration of array in JavaScript: const colors = ['Blue', 'Limegreen', 'Orange', ...

Read More

Checking the equality of array elements (sequence dependent) in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 403 Views

In this article, we'll learn how to check the equality of array elements in a sequence-dependent manner. This means comparing arrays element by element at the same index positions to find matching values or count similarities. Input-Output Scenario Let's look at how sequence-dependent comparison works with two arrays: Array1 = [2, 5, 6, 7, 9, 0]; Array2 = [3, 5, 0, 8, 9, 4]; Output = [5, 9] In the above example, elements 5 and 9 appear at the same index positions (index 1 and 4) in both arrays, making them sequence-dependent matches. ...

Read More

How to clone an array using spread operator in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

In this article, we are going to discuss how to use the spread operator to clone an array in JavaScript. Cloning is the process of copying one array into another array. Previously, the slice() method was used to clone an array, however, ES6 now provides the spread operator (...) to simply clone an array. What is Array Cloning? An Array is a data structure in JavaScript that can hold multiple values at once. Cloning involves copying an array's elements to create a new independent array. ...

Read More

Looping through an array in Javascript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 814 Views

Arrays are linear data structures that store multiple elements in an ordered collection. Each element can be accessed using its index number, starting from 0. const array_name = [item1, item2, ...]; const movies = ["Bahubali", "RRR", "KGF", "Pushpa"]; // Index values: // Bahubali – [0] // RRR – [1] // KGF – [2] // Pushpa – [3] Loops are programming constructs that execute a sequence of instructions repeatedly until a specified condition is met. They're essential for iterating through arrays efficiently. Traditional for Loop The for loop provides complete control over initialization, condition, ...

Read More
Showing 31–40 of 69 articles
Advertisements