Articles on Trending Technologies

Technical articles with clear explanations and examples

Get the size of the screen, current web page and browser window in JavaScript

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

In JavaScript, you can get different dimensions of the screen, browser window, and web page content using various window properties. This is useful for responsive design, creating dynamic layouts, and adjusting content based on available space. We will explore three main categories: Get the Inner Width and Height (viewport size) Get the Outer Width and Height (entire browser window) Get Screen Dimensions Understanding Different Size Properties Property ...

Read More

Implement a JavaScript when an element loses focus

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

When we click on an input element in HTML, it becomes focused and displays an outline. Sometimes, we need to execute JavaScript code when the user moves focus away from an element (when it loses focus). For example, you can validate form fields when users click outside an input, showing error messages like "This field is required" if the input is empty. This is commonly used for real-time form validation. Here, we will learn different approaches to implement JavaScript when an element loses focus. Using the onblur Event Attribute The onblur event attribute triggers when an ...

Read More

Keeping only alphanumerals in a JavaScript string in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 182 Views

We are required to write a JavaScript function that takes in a string that might contain some special characters. The function should return a new string that has all special characters replaced with their corresponding ASCII value, keeping only alphanumeric characters and spaces in their original form. Therefore, let's write the code for this function: Example The code for this will be: const str = 'Th!s !s @ str!ng th@t cont@!ns some special characters!!'; const specialToASCII = str => { let res = ''; for(let i ...

Read More

How to find and return the longest repeating series of numbers in array with JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 644 Views

We are required to write a JavaScript function that takes in an array of Numbers that may contain some repeating elements. The function should return the length of the longest repeating number sequence from the array. For example − If the input array is − const arr = [2, 1, 1, 2, 3, 3, 2, 2, 2, 1]; Then the output should be 3 because the number 2 is repeated 3 times consecutively in the array (and that's the highest number). Using Array.reduce() Method The reduce() method can be used to group ...

Read More

JavaScript - array undefined element count

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 949 Views

In this article, we will learn to count the number of undefined elements in an array using JavaScript. When working with arrays in JavaScript, you may encounter situations where certain elements are either explicitly set as undefined or are missing altogether (often represented by empty slots in sparse arrays). Problem Statement Given an array that may contain undefined values, we need to count how many elements in the array are defined (i.e., not undefined). Input const arr = [12, undefined, "blabla", , true, 44]; Output 4 4 elements are ...

Read More

Subarray sum with at least two elements in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 247 Views

We need to write a JavaScript function that takes an array of integers and a target value, then checks whether there exists a continuous subarray of size at least 2 that sums up to a multiple of the target value. Problem Statement Given an array of integers and a target value k, return true if there exists a continuous subarray of size at least 2 that sums up to n*k (where n is any integer), otherwise return false. For example: Input: arr = [23, 2, 6, 4, 7], target = 6 Output: true ...

Read More

Implement polyfill for Array.prototype.reduce() method in JavaScript

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 1K+ Views

The polyfill is a concept to extend the browser's features using user-defined methods. If the user's browser is not updated, it can happen that browser doesn't support the newer features of any programming language, such as JavaScript. As a developer, we require to check whether the feature is supported by the browser, and if not, we need to invoke a user-defined method. In this tutorial, we will discuss implementing the polyfill for the array.reduce() method. If any browser doesn't support the array.reduce() method, we will invoke the user-defined reduce() method. Before we start with the tutorial, let's ...

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

Grouping nested array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 862 Views

Suppose, we have an array of values like this − const arr = [ { value1:[1, 2], value2:[{type:'A'}, {type:'B'}] }, { value1:[3, 5], value2:[{type:'B'}, {type:'B'}] } ]; We are required to write a JavaScript function that takes in one such array. Our function should then prepare an array ...

Read More

Finding the longest substring uncommon in array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 252 Views

In JavaScript, finding the longest uncommon subsequence in an array involves identifying the longest string that appears only once or doesn't exist as a subsequence in other strings. Understanding Subsequence A subsequence is a sequence derived from another sequence by deleting some characters without changing the order of remaining elements. Any string is a subsequence of itself, and an empty string is a subsequence of any string. Problem Definition We need to find the length of the longest uncommon subsequence among an array of strings. An uncommon subsequence is a subsequence of one string that is ...

Read More
Showing 16301–16310 of 61,297 articles
Advertisements