Object Oriented Programming Articles

Page 68 of 589

JavaScript - array undefined element count

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 938 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 905 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 976 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 911 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

JavaScript - Check if value is a percentage?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 1K+ Views

To check the value for percentage, use a regular expression. When dealing with user input or processing data in JavaScript, it's important to make sure a value is a valid percentage. This article shows you how to check if a value is a percentage using JavaScript, highlighting a useful method that involves regular expressions. Let's say the following is our value: var value = "97%"; To check the value for percentage, we are using a regular expression that matches numbers followed by the % symbol. Using Regular Expression The best way to check ...

Read More

JavaScript input type=submit is not working?

Disha Verma
Disha Verma
Updated on 15-Mar-2026 2K+ Views

The input type submit is not working is one of the common issues that developers face while working with JavaScript forms. To make it work properly, you need to handle form events correctly or prevent the default browser behavior when necessary. This article examines common reasons why a submit button might not work in JavaScript and provides practical solutions to resolve these issues. Common Reasons for Submit Button Issues The following are some common reasons that may lead to this issue: Missing Event Listener − If you haven't added an event ...

Read More

JavaScript Sum of two objects with same properties

Disha Verma
Disha Verma
Updated on 15-Mar-2026 2K+ Views

In JavaScript, summing two objects with identical properties is a common task when working with data aggregation. This involves creating a new object where each property's value is the sum of corresponding values from the input objects. In JavaScript, objects are data structures that store key-value pairs. When you have multiple objects with the same property names, you often need to combine their values mathematically. Understanding the Problem When you have two objects with the same property names, the goal is to create a new object where each property's value is the sum of the matching values ...

Read More
Showing 671–680 of 5,881 articles
« Prev 1 66 67 68 69 70 589 Next »
Advertisements