Javascript Articles

Page 106 of 534

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

If the element repeats, remove all its instances from array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 143 Views

When working with arrays in JavaScript, sometimes you need to remove all instances of elements that appear more than once, keeping only elements that appear exactly once. This is different from typical deduplication where you keep one instance of each duplicate. For example, if the input is: const arr = [763, 55, 43, 22, 32, 43, 763, 43]; console.log("Original array:", arr); Original array: [ 763, 55, 43, 22, 32, 43, 763, 43 ] The output should be: [ 55, 22, 32 ] Notice that 763 and 43 are ...

Read More

Array flattening using loops and recursion in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 669 Views

Array flattening converts nested arrays into a single-level array. JavaScript provides multiple approaches including loops, recursion, and built-in methods. Problem Overview Given a nested array with mixed data types including falsy values, we need to flatten it completely: const arr = [[1, 2, 3], [4, 5, [5, false, 6, [5, 8, null]]], [6]]; console.log("Input:", arr); Input: [ [ 1, 2, 3 ], [ 4, 5, [ 5, false, 6, [Array] ] ], [ 6 ] ] Expected output should be a flat array preserving all values including false and null: ...

Read More

Using recursion to remove consecutive duplicate entries from an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 547 Views

We are supposed to write a function that takes in an array of number/string literals. The function should remove all the redundant consecutive elements of the array without using extra memory space. For example, if the input array is − const arr = [17, 17, 17, 12, 12, 354, 354, 1, 1, 1]; Then the output should be − const output = [17, 12, 354, 1]; Therefore, let's write the code for this function − How the Algorithm Works The recursive function works by checking each element against its ...

Read More

Detecting the largest element in an array of Numbers (nested) in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 257 Views

We need to find the largest number in a nested array of any depth. This problem requires recursion to traverse through all nested levels and compare each number to find the maximum value. For example, if we have this nested array: const arr = [ 34, 65, 67, [ 43, 76, 87, 23, 56, 7, [ 54, 7, 87, 23, 79, 994, 2 ], ...

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

Greatest element in a Multi-Dimensional Array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 194 Views

We have to write a simple function in JavaScript that takes in an array of Numbers (nested to any level) and return the greatest number present in the array. Problem Example If the input array is: const arr = [ 34, 65, 67, [ 43, 76, 87, 23, 56, 7, [ 54, 7, 87, 23, 79, 994, 2 ], ...

Read More

Removing duplicates and inserting empty strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 337 Views

We have to write a function that takes in an array, removes all duplicates from it and inserts the same number of empty strings at the end. Problem Description If we find 4 duplicate values we have to remove them all and insert four empty strings at the end. This maintains the original array length while eliminating duplicates. How It Works The algorithm uses reduce() to iterate through the array. For each element, it checks if the current index matches the last occurrence using lastIndexOf(). If yes, it's the final occurrence and gets added to the ...

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

Constructing a nested JSON object in JavaScript

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

In JavaScript, we often need to construct nested objects from structured data. This article demonstrates how to build a nested JSON object from a string containing paired characters. Problem Statement Given a string with characters in pairs, we need to construct a nested object where each pair becomes a code property, and each level has a sub-object for the next pair. Input string: const str = "AABBCCDDEE"; Expected output structure: const obj = { code: "AA", sub: { ...

Read More
Showing 1051–1060 of 5,340 articles
« Prev 1 104 105 106 107 108 534 Next »
Advertisements