Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 39 of 534
How to do case insensitive string comparison of strings in JavaScript
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 MoreImplementing block search in JavaScript
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 MoreSwapping even and odd index pairs internally in JavaScript
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 MoreContiguous subarray with 0 and 1 in JavaScript
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 MoreFabricJS – How to check if a specified control is visible in Line?
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 MoreCreating a binary spiral array of specific size in JavaScript
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 MoreHow to Create a Profit and Loss Calculator using HTML, CSS, and JavaScript?
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 MoreHow to access HTML elements in JavaScript?
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 MoreCreating a Dynamic Report Card using HTML, CSS, and JavaScript
In this article, we are going to build a dynamic report card using the inputs entered by the user. The user will enter student names and marks for different subjects, and our application will automatically calculate the total marks, average percentage, and pass/fail status. We will be using HTML, CSS, and JavaScript for the implementation. This interactive report card system allows teachers or administrators to quickly generate student performance reports by simply entering marks and clicking a calculate button. Project Overview We will create an HTML form with input fields for student name ...
Read MoreJavaScript: How to allow users to change the font-size of a webpage?
In this article, we will explore how to create a dynamic font size control feature that allows users to adjust the font size of webpage content. This accessibility feature is commonly found on government websites and helps users customize text size for better readability. We'll implement this functionality using both vanilla JavaScript and jQuery approaches to give you flexibility in your implementation. Method 1: Using jQuery This example demonstrates a simple implementation with increase and decrease buttons that modify the font size of specific content areas. Change Font ...
Read More