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 206 of 534
How to remove elements from an array until the passed function returns true in JavaScript?
In JavaScript, there are various ways to remove elements from an array until the passed function returns true. This tutorial explores three different approaches with practical examples. Understanding "Remove Until Function Returns True" This operation means collecting elements from the beginning of an array, stopping when a condition is met. It's similar to "taking elements while a condition is false" or "dropping elements until a condition is true". Using Array.prototype.filter() The filter() method creates a new array with elements that pass a test function. For removing elements until a condition is met, we filter elements that ...
Read MoreWhat is difference between Microtask Queue and Callback Queue in asynchronous JavaScript?
In asynchronous JavaScript, there are two ways to schedule tasks – microtask queue and callback queue. Both queues are handled differently by the JavaScript engine, with microtasks having higher priority than callbacks. Event Loop Overview The event loop processes tasks in this order: call stack → microtask queue → callback queue. Understanding this priority system is crucial for predicting execution order in asynchronous code. Call Stack (Synchronous) Highest Priority Microtask Queue ...
Read MoreHow to set the minimum allowed scale value of Rectangle using FabricJS?
In this tutorial, we are going to learn how to set the minimum allowed scale of Rectangle using FabricJS. Rectangle is one of the various shapes provided by FabricJS. In order to create a rectangle, we will have to create an instance of fabric.Rect class and add it to the canvas. We can customize a rectangle object by adding a fill colour to it, eliminate its borders or even make changes in its dimensions. Similarly, we can also set its minimum allowed scale by using the minScaleLimit property. Syntax new fabric.Rect({ minScaleLimit : Number }: Object) ...
Read MoreHow to return true if the parent element contains the child element in JavaScript?
In this tutorial, we are going to look at how we can return true if the parent element contains the child element in JavaScript. Assuming you have two HTML elements, a parent element, and a child element, and you want to know if the parent element contains the child element. Using the Node.contains() method The Node interface's contains() method returns a Boolean value, indicating whether a node is a descendant of a given node or not. If you want to know if the parent element contains the child element, you can use the Node.contains() method. Syntax ...
Read MoreHow to convert a string into an integer without using parseInt() function in JavaScript?
The parseInt() is a built-in function in JavaScript that parses a string and returns an integer. However, there are times when we want to convert a string into an integer without using this function. In this article, we'll explore several alternative methods to achieve this conversion. Using the Unary Plus Operator One way to convert a string into an integer is by using the unary plus operator (+). This operator converts its operand into a number. For instance, the following program converts the string "123" into the number 123: Unary Plus ...
Read MoreHow to convert a 2D array to a CSV string in JavaScript?
The CSV (Comma Separated Values) file format is a popular way of exchanging data between applications and data stores. The CSV file format is simple and easy to understand, and many applications and programming languages support it. In JavaScript, there are several ways to convert a 2D array into a CSV string. In this tutorial, we'll look at effective methods: using Array.map() with join(), and a manual approach for handling special cases. Using Array.map() with join() (Recommended) The most straightforward approach is to use Array.map() to process each row and join() to combine elements with commas. ...
Read MoreHow to calculate GCD of two or more numbers/arrays in JavaScript?
The greatest common divisor (GCD) of two or more numbers, also known as the greatest common factor (GCF) or highest common factor (HCF), is the largest positive integer that divides a given number without a remainder. In other words, the GCD is the largest number that is a divisor of both numbers. For example, the GCD of 24 and 36 is 12. Understanding the Euclidean Algorithm The Euclidean algorithm is the most efficient method to calculate GCD. It works by repeatedly applying the formula: gcd(a, b) = gcd(b, a % b) until one number becomes zero. ...
Read MoreHow to return HTML or build HTML using JavaScript?
When building web applications, there are often times when you need to dynamically generate HTML on the client-side. This can be done using JavaScript, and there are different ways to go about it. In this article, we'll show you how to return HTML or build HTML using JavaScript. Method 1: Returning HTML from a Function One way to dynamically generate HTML is to return a string of HTML from a function. For example, let's say we have a function that generates a list item: Returning HTML from Functions ...
Read MoreHow to get the first non-null/undefined argument in JavaScript?
In JavaScript, there are often times when we need to find the first non-null/undefined argument in a function. This can be a tricky task, but luckily there are a few methods that can help us accomplish this. Using Array.prototype.find() One method that can be used to get the first non-null/undefined argument in JavaScript is the Array.prototype.find() method. This method returns the value of the first element in an array that passes a given test. In our case, we can use this method to find the first non-null/undefined argument by passing a test that checks if the argument is ...
Read MoreHow to run a given array of promises in series in JavaScript?
In JavaScript, there is a method called "Promise.all" that allows you to run an array of promises in parallel. However, sometimes you may want to run your promises in series instead. This can be useful if you want to make sure that each promise is executed one after the other, or if you need to use the result of one promise in the execution of the next promise. There are a few different ways that you can run an array of promises in series in JavaScript. In this article, we'll take a look at a few of them. ...
Read More