Front End Technology Articles

Page 319 of 652

JavaScript - Finding the third maximum number in an array

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 1K+ Views

In this article, we will learn to find the third maximum unique number in an array of JavaScript, or the largest number if there are fewer than three unique values. We will be using three methods: a single-pass approach for efficiency, a sorting method to identify the number after removing duplicates, and a combination of Set and Max-Heap for optimal handling of large datasets. Problem Statement Given an array of integers, find the third maximum unique number. If the array contains fewer than three unique numbers, return the largest number in the array. Input: const nums = ...

Read More

JavaScript - Complementary Colors Builder

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 1K+ Views

In this article, we will learn to build a JavaScript function that calculates the complementary color for a given hex color code. In web development, working with colors and their relationships is an essential aspect of design and user interface. One of the concepts that designers often use is complementary colors—colors that are opposite each other on the color wheel, providing contrast and enhancing visual appeal. You can try our Online Color Picker Tool to create new colors. Understanding Complementary Colors The following concepts help us understand complementary colors: Complementary Colors: ...

Read More

JavaScript - array undefined element count

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 950 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

JavaScript: take every nth Element of Array and display a fixed number of values?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 1K+ Views

In this article, we will learn to extract every nth element from an array and display a fixed number of values in Javascript. The objective is to filter out every second element (or more generally every nth element) from an array and limit the result to a specified count of elements. We will explore different approaches in JavaScript for achieving this functionality, each offering a unique way to solve the problem. Problem Statement Let's say you have an array that takes every nth element. Display a fixed number of values after extracting the elements. Input Let's say the ...

Read More

JavaScript function to prepend string into all the values of array?

Sakshi Jain
Sakshi Jain
Updated on 15-Mar-2026 921 Views

In this article, we will learn to prepend a string into all the values of an array in JavaScript. Arrays are versatile data structures used to store multiple elements of similar or mixed types. A common operation is prepending a string to each element of an array, which involves adding a specified string at the beginning of each element. Problem Statement Given a string to prepend and an array of values, we need to add the string at the beginning of each array element and return the modified array. Example Input: const str = "Hello"; ...

Read More

JavaScript Quicksort Recursive

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 1K+ Views

In this article, we will learn to implement Quicksort recursively in JavaScript. Quicksort is one of the most efficient and widely used sorting algorithms, known for its divide-and-conquer approach. What is Quicksort? Quicksort is a divide-and-conquer sorting algorithm that sorts an array by selecting a pivot element and partitioning the array into two subarrays: elements smaller than the pivot and elements greater than or equal to the pivot. It then recursively sorts the subarrays. Quicksort Process ...

Read More

Create array from JSON object JavaScript

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 2K+ Views

In this article, we will learn to create an array from JSON data in JavaScript. JSON is a widely used format for storing and exchanging data. A common use case involves extracting specific data from a JSON object or array and converting it into a separate array for further processing. What is JSON Data? JSON (JavaScript Object Notation) is a lightweight data format commonly used to store and exchange data between a server and a client. It represents data as key-value pairs and is easy for both humans and machines to read and write. In JavaScript, JSON objects ...

Read More

JavaScript: Adjacent Elements Product Algorithm

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 982 Views

In this article, we will learn to calculate the adjacent elements product with the help of JavaScript functionalities. This problem is often asked in coding interviews or algorithm challenges, and it tests one's understanding of array manipulation and performance optimization. Problem Statement Given an array of integers, your task is to return the largest product that can be obtained by multiplying any two adjacent numbers in the array. For example − Input: [5, 1, 2, 3, 1] Output: 6 The adjacent elements are (5, 1), (1, 2), (2, 3), and (3, 1). The largest ...

Read More

JavaScript Array Ranking

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

In this article, we will learn to rank elements in arrays using JavaScript. Ranking elements in an array is common in various applications, such as sorting scores, evaluating performance, or analyzing data. What is Array Ranking? Array ranking involves assigning a rank to each element of an array based on its value, where the largest value gets the highest rank and the smallest value gets the lowest rank. This ranking can be extended to multiple arrays to analyze and compare data across different datasets. Problem Statement We are given multiple arrays of numbers. The task is ...

Read More

Appending Suffix to Numbers in JavaScript

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 15-Mar-2026 1K+ Views

Appending suffixes to numbers in JavaScript is used to add ordinal indicators (like "st", "nd", "rd", and "th") to the end of a number to denote its position in a sequence. This is useful for displaying dates, rankings, or other numeric data. A custom function can be created to append the correct suffix to a given number. The function handles special cases for numbers ending in 11, 12, and 13, and applies the appropriate suffix based on the last digit for other numbers. Rules for Ordinal Suffixes ...

Read More
Showing 3181–3190 of 6,519 articles
« Prev 1 317 318 319 320 321 652 Next »
Advertisements