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 19 of 534
JavaScript program for Shortest Un-Ordered SubarrayJavaScript program for Shortest Un-Ordered Subarray
The problem statement requires finding the shortest un-ordered subarray in an array of integers. In other words, we need to identify the smallest subarray in which the elements are not sorted in ascending or descending order. This problem can be solved through various approaches, but in this article, we will discuss a simple and efficient solution using JavaScript. So first we will start by defining what an un-ordered Subarray is, then understand the problem statement in detail and then proceed to explain the step-by-step solution using examples and code snippets. By the end of this article, you will have ...
Read MoreExplain about IIFEs in JavaScript
In the world of JavaScript, there are various techniques and patterns that developers use to write efficient, maintainable code. One such powerful programming technique is the Immediately Invoked Function Expression (IIFE). In this article, we'll dive into IIFEs, their benefits, and how to implement them using different approaches. We'll also explore some practical examples to help you understand their applications in real-world scenarios. What is an IIFE? An IIFE is a function expression that is executed immediately after its definition. It creates its own scope, preventing variables from polluting the global namespace. Syntax (function() { ...
Read MoreJavaScript program for Sort the given matrix
Sorting a given matrix using JavaScript is a fundamental operation in programming. Sorting is the process of arranging the elements of a collection or matrix in a particular order. It is essential to make searching and other operations more efficient. In this article, we will discuss how to sort a given matrix using the JavaScript programming language. Problem Statement Given an n x n matrix, we need to sort all elements so that the matrix follows "strict order" - each row is sorted in ascending order, and for any row i where 1 ≤ i ≤ n-1, ...
Read MoreJavaScript Program for Sorting a Linked List of 0s, 1s, And 2s
In this tutorial, we will learn the JavaScript program for sorting a linked list of 0s, 1s, and 2s. Sorting algorithms are essential for any programming language, and JavaScript is no exception. Sorting a linked list of 0s, 1s, and 2s is a common problem that developers encounter in coding interviews and real-world applications. So, let's dive in and explore how to sort a linked list of 0s, 1s, and 2s using JavaScript programming. What is Sorting? Sorting is the process of arranging elements in a specific order, either ascending or descending. It is a fundamental operation ...
Read MoreFind 1st January be Sunday between a range of years in JavaScript?
Finding years where January 1st falls on a Sunday is useful for planning events, scheduling, and calendar calculations. JavaScript's Date object makes this straightforward by providing methods to determine the day of the week. How It Works The approach uses JavaScript's Date constructor and getDay() method. The getDay() method returns 0 for Sunday, 1 for Monday, and so on. We iterate through a range of years, create a Date object for January 1st of each year, and check if it's a Sunday. Method 1: Direct Sunday Check This method directly checks if getDay() returns 0 (Sunday): ...
Read MoreHow do you make synchronous HTTP request in JavaScript?
Making synchronous HTTP requests in JavaScript blocks code execution until the response arrives. While generally discouraged, certain scenarios may require this approach. This article explores methods to create synchronous HTTP requests in JavaScript. Why Synchronous Requests? Synchronous requests pause execution until completion, which can freeze the browser. However, they're sometimes needed for: Critical data required before proceeding Sequential API calls with dependencies Legacy code compatibility Algorithm The basic steps for making synchronous HTTP requests: Create an HTTP request object ...
Read MoreHow to Send Axios Delete to the Backend ReactJS in JavaScript
Sending DELETE requests to a backend is a common requirement in React applications. Axios provides multiple ways to handle DELETE operations, making it easy to remove data from your server. What is Axios DELETE? Axios DELETE is an HTTP method used to remove resources from a server. In React applications, you'll typically use it to delete user records, posts, comments, or any other data that needs to be removed from your backend database. Algorithm Here are the steps to send an Axios DELETE request in React: Import Axios − Include the Axios library in ...
Read MoreHow to concatenate regex literals in JavaScript?
Regular expressions (regex literals) are patterns used to match character combinations in strings. Sometimes, you need to combine multiple regex patterns into a single expression. Unlike strings, regex literals cannot be concatenated directly with the '+' operator. To concatenate regex literals, you must extract their source patterns and flags, combine them properly, and create a new RegExp object. Syntax Follow this approach to concatenate regex literals: let allFlags = regex1.flags + regex2.flags; let uniqueFlags = [...new Set(allFlags.split(''))].join(''); let combined = new RegExp(regex1.source + regex2.source, uniqueFlags); This extracts the source patterns and flags from ...
Read MoreFind the OR and AND of Array elements using JavaScript
In JavaScript, we can use the '&&' operator to perform the AND operation between two elements and the '||' operator to perform OR operation between two elements. Here, we will learn to perform OR and AND operations between every element of the array using different approaches. Use the for Loop We can use the for loop to iterate through the array elements and perform OR or AND operations with all array elements. Syntax Users can follow the syntax below to use the for loop to take OR or AND operation of every element. ...
Read MoreFinding the time elapsed in JavaScript
Finding time elapsed in JavaScript is essential for performance monitoring, measuring execution time, and tracking user interactions. JavaScript provides several built-in methods to calculate time differences accurately. In this tutorial, we'll explore three different approaches: the Date() object for general time calculations, console.time() for debugging, and performance.now() for high-precision measurements. Using the Date() Object The Date() constructor returns the current timestamp in milliseconds since January 1, 1970 (Unix epoch). We can calculate elapsed time by finding the difference between two timestamps. Syntax let startTime = new Date(); let endTime = new Date(); let timeElapsed ...
Read More