Javascript Articles

Page 39 of 534

Return the sum of two consecutive elements from the original array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 2K+ Views

An Array is known as collection of similar data elements which are stored at contiguous memory locations. Array is such a simple data structure where we can access each data element in the array with the help index numbers, which starts from 0. The following is the basic declaration of array in JavaScript − const mobiles = ["SAMSUNG", "ONEPLUS", "APPLE"]; Sum of Two Consecutive Elements of an Array 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 ...

Read More

How to dynamically create radio buttons using an array in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 6K+ Views

Creating radio buttons dynamically using an array in JavaScript is a useful way to provide users with multiple options for input. When the user clicks on one of the radio buttons, it will be selected and any other choices will be deselected automatically. This process can be automated by looping through an array that contains all the possible values and creating a new radio button element for each item in the array. To dynamically create radio buttons using an array, use the concept of createElement() and appendChild(). Let's look at the concept to understand more about dynamically creating ...

Read More

How to do case insensitive string comparison of strings in JavaScript

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

In this tutorial, we will learn how to do a case-insensitive string comparison of strings in JavaScript. Case insensitive comparison means strings should be considered equal regardless of whether they are written in lowercase or uppercase letters. This technique is commonly used in search functionality, where "TutorialsPoint" and "tutorialspoint" should be treated as identical. There are four main methods to perform case-insensitive string comparisons: toUpperCase() toLowerCase() localeCompare() RegExp() Using the toUpperCase() Method The toUpperCase() method converts all alphabetic ...

Read More

Implementing block search in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 372 Views

Block Search is a searching algorithm for sorted arrays that improves upon linear search by jumping ahead in fixed steps rather than checking every element. It combines the efficiency of skipping elements with linear search for the final location. How Block Search Works The algorithm divides the array into blocks of size √n and performs these steps: Jump through blocks of size √n until finding a block where the target might exist Perform linear search within that specific block Return the index if found, or -1 if not found Block Search ...

Read More

Swapping even and odd index pairs internally in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 574 Views

We are required to write a JavaScript function that takes in an array of literals as the first and the only argument. Our function should swap each consecutive even index with each other, and swap each consecutive odd indexes with each other. The function should do these swappings in place. For example, if the input array is: const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8]; Then the array should become: const output = [2, 3, 0, 1, 6, 7, 4, 5, 8]; Because 0 and 2 ...

Read More

Contiguous subarray with 0 and 1 in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 356 Views

In JavaScript, finding the longest contiguous subarray with equal numbers of 0s and 1s in a binary array is a classic problem that can be solved efficiently using a hash map approach. Problem Statement Given a binary array containing only 0s and 1s, find the length of the longest contiguous subarray that contains an equal number of 0s and 1s. For example, with the input array: const arr = [1, 0, 0, 1, 0, 1, 0, 0]; console.log("Input array:", arr); Input array: [1, 0, 0, 1, 0, 1, 0, 0] ...

Read More

FabricJS – How to check if a specified control is visible in Line?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 376 Views

In this article, we are going to learn about how to check if a specified control is visible in Line using FabricJS. A Line element is one of the basic elements provided in FabricJS. It is used for creating straight lines. Because line elements are geometrically one-dimensional and do not contain an interior, they are never filled. We can create a line object by creating an instance of fabric.Line, specifying the x and y coordinates of the line and adding it to the canvas. In order to check if a specified control is visible in Line object, we use the ...

Read More

Creating a binary spiral array of specific size in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 246 Views

We are required to write a JavaScript function that takes in a number n. Our function should construct and return an array of N * N order (2-D array), in which the 1s take all the spiralling positions starting from [0, 0] and all the 0s take non-spiralling positions. Therefore, for n = 5, the output will look like: [ [ 1, 1, 1, 1, 1 ], [ 0, 0, 0, 0, 1 ], [ 1, 1, 1, 0, 1 ], [ 1, 0, 0, 0, 1 ], ...

Read More

How to Create a Profit and Loss Calculator using HTML, CSS, and JavaScript?

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 2K+ Views

In this article, we are going to create a profit and loss calculator using JavaScript. We will be using basic math formulas to calculate the profit and loss, returning the result in percentage along with the actual values. To calculate profit and loss, we need two values: CP (Cost Price) and SP (Selling Price). Formulas to Calculate Profit and Loss Profit: SP − CP Profit Percentage: (Profit/CP) × 100 Loss: CP − SP Loss Percentage: (Loss/CP) × 100 Creating the Calculator ...

Read More

How to access HTML elements in JavaScript?

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 19K+ Views

In JavaScript, accessing HTML elements is fundamental for creating dynamic web pages. The Document Object Model (DOM) provides several methods to select and manipulate HTML elements based on different criteria. Get HTML element by Id Get HTML element by className Get HTML element by Name Get HTML element by tagName Get HTML element by CSS Selector Get HTML element by Id The getElementById() method retrieves a single element using its unique ID attribute. This is the most efficient way to ...

Read More
Showing 381–390 of 5,340 articles
« Prev 1 37 38 39 40 41 534 Next »
Advertisements