Articles on Trending Technologies

Technical articles with clear explanations and examples

Sum all duplicate value in array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 501 Views

We are required to write a JavaScript function that takes in an array of numbers with duplicate entries and sums all the duplicate entries to one index. For example − If the input array is − const input = [1, 3, 1, 3, 5, 7, 5, 4]; Then the output should be − const output = [2, 6, 7, 10, 4]; Using Map to Track and Sum Duplicates The most efficient approach is to use a Map to count occurrences and then multiply each unique value by its count: ...

Read More

Adding two values at a time from an array - JavaScript

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

Let's say, 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 consecutive elements from the original array. For example, if the input array is − const arr = [3, 6, 3, 87, 3, 23, 2, 2, 6, 8]; Then the output should be − const output = [9, 90, 26, 4, 14]; Example Following is the code − const arr = [3, 6, 3, 87, 3, 23, 2, 2, 6, 8]; ...

Read More

How to search the alternate text of an image-map area in JavaScript?

Sravani S
Sravani S
Updated on 15-Mar-2026 211 Views

To search the alternate (alt) text of an image-map area in JavaScript, use the alt property. This property allows you to access or modify the alternative text that describes the image map area for accessibility purposes. Syntax // Get alt text let altText = areaElement.alt; // Set alt text areaElement.alt = "new alt text"; Example: Accessing Alt Text of Image Map Area ...

Read More

Does HTML5 allow you to interact with local client files from within a browser?

varun
varun
Updated on 15-Mar-2026 411 Views

HTML5 allows web applications to interact with local client files through powerful APIs. These interfaces enable browsers to access the user's file system, read binary data, and handle file operations that were previously impossible with standard web technologies. HTML5 File APIs HTML5 provides three main APIs for file interaction: File API - Read file contents and metadata File System API - Access file system structure (deprecated in modern browsers) File Writer API - Write data to files (limited browser support) Reading Local Files The ...

Read More

How to check if a document is ready in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 788 Views

In JavaScript, you can check if the DOM is fully loaded using document.readyState or event listeners. This is crucial for ensuring your scripts run after the HTML structure is ready. Understanding document.readyState The document.readyState property has three possible values: "loading" - The document is still loading "interactive" - The document has loaded but resources like images may still be loading "complete" - The document and all resources have finished loading Method 1: Using document.readyState Document Ready ...

Read More

How to find a group of three elements in an array whose sum equals some target sum JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 628 Views

We need to write a function that finds three elements in an array whose sum equals a target value. The function should return the indices of these three elements, or -1 if no such triplet exists. Approach We'll use a two-step approach: Create a twoSum() helper function that finds two numbers adding up to a target sum Iterate through each element and use twoSum() to find the remaining two elements This approach has O(N²) time complexity, where N is the array length. How It Works The twoSum() function uses a hash map ...

Read More

Find unique and biggest string values from an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 295 Views

In JavaScript, we often need to filter arrays to get unique values and sort them by specific criteria. This article demonstrates how to find the longest unique string values from an array of objects. Problem Statement Given an array of objects with text properties, we need to create a function that returns n objects with the longest unique string values. If fewer than n unique objects exist, return all unique objects. const arr = [ {text: 'use'}, {text: 'secur'}, {text: 'form'}, ...

Read More

Create new array without impacting values from old array in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 332 Views

In JavaScript, directly assigning an array to a new variable creates a reference to the original array, not a copy. This means changes to the new variable will affect the original array. To create a truly independent copy, you need to use specific cloning methods. The Problem with Direct Assignment When you assign an array directly, both variables point to the same array in memory: var originalArray = ["John", "Mike", "Sam", "Carol"]; var newArray = originalArray; // This creates a reference, not a copy newArray.push("David"); console.log("Original array:", originalArray); console.log("New array:", newArray); ...

Read More

Counting the clusters of positive numbers - JavaScript Arrays

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 323 Views

Let's say, we have an array of numbers like this − const arr = [-1, -2, -1, 0, -1, -2, -1, -2, -1, 0, 1, 0]; We are required to write a JavaScript function that counts the consecutive groups of non-negative (positives and 0) numbers in the array. Like here we have consecutive non-negatives from index 3 to 3 (only one element, but still a cluster) which forms one group and then from index 9 to end of array forms the second group. Therefore, for this array, the function should return 2. How It Works ...

Read More

How Is Infinity converted to Boolean in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 619 Views

In JavaScript, Infinity and -Infinity are special numeric values representing positive and negative infinity. When converting these values to Boolean, they always evaluate to true because they are considered "truthy" values. This tutorial demonstrates three methods to convert Infinity values to Boolean in JavaScript: Using the Boolean() Method Using the Logical NOT(!) Operator Converting Infinity to String to Boolean Using the Boolean() Method The Boolean() constructor converts any value to its boolean equivalent. For Infinity and -Infinity, this method returns true since both are truthy ...

Read More
Showing 18491–18500 of 61,297 articles
Advertisements