Found 6710 Articles for Javascript

How to calculate GCD of two or more numbers/arrays in JavaScript?

Imran Alam
Updated on 01-Jul-2022 12:25:50

728 Views

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.How to calculate the GCD of two numbers?There are a few different ways to calculate the GCD of two numbers, but the most common method is the Euclidean algorithm.The Euclidean algorithm is an iterative method that starts with two numbers, ... Read More

How to convert a 2D array to a CSV string in JavaScript?

Imran Alam
Updated on 21-Jul-2022 14:34:55

1K+ Views

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 a number of ways to convert an array of data into a CSV string. In this tutorial, we'll look at two popular methods: the Array.join() method and the JSON.stringify() method.Using the Array.join() MethodThe Array.join() method is a built-in method of the JavaScript Array object. It can be used to join the elements of an array into a single string. The ... Read More

How to convert a string into an integer without using parseInt() function in JavaScript?

Imran Alam
Updated on 01-Jul-2022 12:06:56

2K+ Views

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 how to do just that.Using the unary plus operatorOne 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 −Example 1    Examples                   ... Read More

How to return true if the parent element contains the child element in JavaScript?

Imran Alam
Updated on 01-Jul-2022 08:51:52

7K+ Views

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() methodThe 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.Here's a simple example −    Some text The ... Read More

How to set the minimum allowed scale value of Rectangle using FabricJS?

Rahul Gurung
Updated on 30-Jun-2022 14:33:09

164 Views

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.Syntaxnew fabric.Rect({ minScaleLimit : Number }: Object)ParametersOptions (optional) − This parameter is an Object ... Read More

What is difference between Microtask Queue and Callback Queue in asynchronous JavaScript?

Imran Alam
Updated on 01-Jul-2022 08:41:46

3K+ Views

In asynchronous JavaScript, there are two ways to schedule tasks – microtask queue and callback queue. Both queues are handled differently by the JavaScript engine.Microtask QueueA Microtask queue is a queue of tasks that are executed after the current task. The microtask queue is handled by the JavaScript engine before it moves on to the next task in the callback queue.ExampleHere’s an example of how microtask queue works −    Examples               console.log('start');         setTimeout(function() {          console.log('setTimeout');       }, 0);   ... Read More

How to remove elements from an array until the passed function returns true in JavaScript?

Imran Alam
Updated on 01-Jul-2022 08:33:48

445 Views

In JavaScript, there are various ways to remove elements from an array until the passed function returns true. In this tutorial, we are going to look at 3 methods in detail.Using Array.prototype.filter()The Array.prototype.filter() method can be used to remove elements from an array until the passed function returns true. Please refer to the Array filter() method for more details.Example 1The following code shows how to use this method −    Examples                   var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];       function ... Read More

How to set the border scale factor of Rectangle using FabricJS?

Rahul Gurung
Updated on 30-Jun-2022 09:04:44

437 Views

In this tutorial, we are going to set the border scale factor 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 use the borderScaleFactor property which specifies the scale factor of the object's controlling borders.Syntaxnew fabric.Rect({ borderScaleFactor: Number }: Object)ParametersOptions (optional) − This parameter is an Object which provides additional customizations to our rectangle. Using this parameter, properties such as colour, cursor, stroke width and a lot of other properties can be ... Read More

How to lock the rotation of Rectangle using FabricJS?

Rahul Gurung
Updated on 29-Jun-2022 11:52:19

687 Views

In this tutorial, we are going to learn how to lock the rotation of a Rectangle using FabricJS. Just as we can specify the position, colour, opacity and dimension of a rectangle object in the canvas, we can also specify whether we want it to rotate or not. This can be done by using the lockRotation property.Syntaxnew fabric.Rect({ lockRotation : Boolean }: Object)ParametersOptions (optional) − This parameter is an Object which provides additional customizations to our rectangle. Using this parameter, properties such as colour, cursor, stroke width, and a lot of other properties can be changed related to the object ... Read More

How to lock the horizontal skewing of Rectangle using FabricJS?

Rahul Gurung
Updated on 29-Jun-2022 11:47:51

501 Views

In this tutorial, we are going to learn how to lock the horizontal skewing of a Rectangle using FabricJS. Just as we can specify the position, colour, opacity and dimension of a rectangle object in the canvas, we can also specify whether we want to stop skewing an object horizontally. This can be done by using the lockSkewingX property.Syntaxnew fabric.Rect({ lockSkewingX : Boolean }: Object)ParametersOptions (optional) − This parameter is an Object which provides additional customizations to our rectangle. Using this parameter, properties such as colour, cursor, stroke width, and a lot of other properties can be changed related to ... Read More

Advertisements