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
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to simulate a click with JavaScript ?
Simulating a click with JavaScript allows you to programmatically trigger click events on elements without user interaction. This is useful for automation, testing, or creating dynamic user interfaces. What is Click Simulation? Click simulation means programmatically triggering a click event on an HTML element using JavaScript's click() method or dispatchEvent(). This executes the same actions that would occur if a user physically clicked the element. Method 1: Using the click() Method The simplest way to simulate a click is using the built-in click() method: ...
Read MoreConvert array into array of subarrays - JavaScript
We are required to write a JavaScript function that takes in an array of literals and returns a new array that have elements of the original array chunked into subarrays of length exactly 2. Now if the length of original array is not exactly divisible by 2, then the last subarray should have only one element. For example, if the input array is: const arr = [1, 2, 3, 4, 5, 6, 7]; Then the output should be: const output = [[1, 2], [3, 4], [5, 6], [7]] Using Loop-based ...
Read MoreHow to recognize when to use : or = in JavaScript?
The colon (:) is used to define properties in objects, while the equal sign (=) is used to assign values to variables. Understanding when to use each is fundamental in JavaScript. Using Colon (:) in Objects The colon separates property names from their values when creating object literals: var studentDetails = { "studentId": 101, "studentName": "John", "studentSubjectName": "Javascript", "studentCountryName": "US" }; console.log(studentDetails); { studentId: 101, studentName: 'John', studentSubjectName: 'Javascript', ...
Read MoreHow to format date value in JavaScript?
JavaScript provides several methods to format dates according to your requirements. The built-in Date object offers various formatting options, from simple string conversion to locale-specific formatting. Using toLocaleDateString() Method The toLocaleDateString() method formats dates according to locale and custom options, providing flexible date formatting. Example Here's how to format dates with custom options using toLocaleDateString(): var options = { year: 'numeric', ...
Read MoreFinding union of two sets in JavaScript
The union of two sets is the combination of all unique elements from both sets. In JavaScript, we can find the union of two arrays using several approaches. What is Union Set Union Set is the set made by combining the elements of two sets. Therefore, the union of sets A and B is the set of elements in A, or B, or both. For example − If we have two sets denoted by two arrays like this − const arr1 = [1, 2, 3]; const arr2 = [100, 2, 1, 10]; ...
Read MoreIs a number sum of two perfect squares in JavaScript
Perfect Square Numbers A natural number in mathematics is called a perfect square if it can be obtained by multiplying any other natural number by itself. For instance, 9, 16, 81, 289 are all perfect squares because: 9 = 3 × 3 16 = 4 × 4 81 = 9 × 9 289 = 17 × 17 We need to write a JavaScript function that takes a natural number as input and determines whether it can be expressed ...
Read MoreFinding the 1-based index of a character in alphabets using JavaScript
We are required to write a JavaScript function that takes in a lowercase English alphabet character. Our function should return the character's 1-based index in the alphabets. Problem Given a lowercase English alphabet character, we need to find its position in the alphabet where 'a' = 1, 'b' = 2, 'c' = 3, and so on. Method 1: Using String indexOf() We can create a string containing all alphabets and use indexOf() to find the position: const char = 'j'; const findCharIndex = (char = '') => { const legend ...
Read MoreHow to lock the rotation of Rectangle using FabricJS?
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. Syntax new fabric.Rect({ lockRotation : Boolean }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our ...
Read MoreHow to set the text alignment of Text using FabricJS?
In this tutorial, we are going to learn how to set the text alignment of text in Text using FabricJS. We can display text on canvas by adding an instance of fabric.Text. Not only does it allow us to move, scale and change the dimensions of the text but it also provides additional functionality like text alignment, text decoration, line height which can be obtained by the properties textAlign, underline and lineHeight respectively. Similarly, we can also set its text alignment by using the textAlign property. Syntax new fabric.Text(text: String , { textAlign : String }: Object) ...
Read MoreHow to set the border colour of a Line in FabricJS?
In this tutorial, we are going to learn about how to set the border colour of Line in 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. The property borderColor allows us to manipulate the colour of the border when our object is active. ...
Read More