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 change the source of an Image using FabricJS?
In this tutorial, we are going to learn how to change the source of an Image using FabricJS. Source can be a new url of image also. We can create an Image object by creating an instance of fabric.Image. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to change the source of an Image, we use the setSrc method. Syntax setSrc(src: String, callback: function, options: Object): fabric.Image Parameters src − This parameter accepts a String which ...
Read MoreHow to check whether an array is a subset of another array using JavaScript?
The first array is the subset of the second array if the second array contains all elements of the first array. So, sometimes we may be required to check if one array is the subset of another. In this tutorial, we will learn to check if one array is a subset of another array using three different approaches. Using the for loop and array.includes() method Users can use the for loop to iterate through every element of the first array. After that, they can use the includes() method to check if the second array contains every element ...
Read MoreHow to replace some preceding characters with a constant 4 asterisks and display the last 3 as well - JavaScript?
In JavaScript, you can mask sensitive data by replacing preceding characters with asterisks while keeping the last few characters visible. This is commonly used for phone numbers, credit cards, or account numbers. Problem Statement Given these input values: '6778922' '76633 56 1443' '8888 4532 3232 9999' We want to replace all preceding characters with 4 asterisks and display only the last 3 characters: **** 922 **** 443 **** 999 Using replace() with Regular Expression The replace() method with a regex pattern can capture the last 3 characters and replace ...
Read MoreFinding degree of subarray in an array JavaScript
The degree of an array is defined as the maximum frequency of any element in the array. Finding the shortest subarray with the same degree is a common programming problem that involves tracking element frequencies and their positions. const arr = [1, 2, 3, 3, 5, 6, 4, 3, 8, 3]; console.log("Array:", arr); console.log("Degree of array: 4 (element 3 appears 4 times)"); Array: [ 1, 2, 3, 3, 5, 6, 4, 3, 8, 3 ] Degree of array: 4 (element 3 appears 4 times) Our task is to find the length of the ...
Read MoreCounting number of vowels in a string with JavaScript
We are required to write a JavaScript function that takes in a string. The function should count the number of vowels present in the string. The function should prepare an object mapping the count of each vowel against them. Example The code for this will be − const str = 'this is an example string'; const vowelCount = (str = '') => { const splitString = str.split(''); const obj = {}; const vowels = "aeiou"; splitString.forEach((letter) => { ...
Read MoreConsecutive ones with a twist in JavaScript
We are required to write a JavaScript function that takes in a binary array (an array that consists of only 0 and 1), arr, as the only argument. Our function should find the maximum number of consecutive 1s in this array if we can flip at most one 0. Problem Statement Given a binary array, find the maximum number of consecutive 1s we can achieve by flipping at most one 0 to 1. For example, if the input array is: [1, 0, 1, 1, 0] Then the output should be: 4 ...
Read MoreHow to create HTML list from JavaScript array?
In this tutorial, we will explore multiple ways to create an HTML list from a JavaScript array. While you can manually create HTML lists using ul (unordered list) and li (list item) tags, this becomes impractical when dealing with dynamic data or large arrays. JavaScript provides efficient methods to dynamically generate HTML lists from array data. Let's examine three different approaches to accomplish this task. Method 1: Using the for Loop The simplest approach uses a traditional for loop to iterate through the array and create list items dynamically using createElement() and appendChild(). ...
Read MoreHow to find the translation matrix of a Polygon object using FabricJS?
A translation slides an object to a fixed distance in a given direction. We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to find the translation matrix, we use the _calcTranslateMatrix() method. This method returns an Array with given values [1, 0, 0, 1, A, B]; where A is the X-coordinate and ...
Read MoreHow to check whether an object exists in JavaScript?
The object contains the properties and their values in JavaScript. We can create an object using the curly ({}) braces. It's similar to the variables, but we assign an object value rather than assigning the number, string, or boolean value to the variable. So, here we will learn to check if the object exists in JavaScript in this tutorial. In short, we have to learn ways to check the existence of object variables. Using the try-catch Statement Generally, we use the try-catch statement to handle errors in JavaScript. We can try to access the object or its ...
Read MoreHow to uncheck a radio button using JavaScript/jQuery?
Sometimes, we require to uncheck a radio button using JavaScript or jQuery. For example, we use the radio button in the form. When the user presses the clear form button, we need to uncheck all radio buttons and allow again users to choose any option from the radio button. In this tutorial, we will learn various methods to uncheck single or multiple radio buttons using jQuery or JavaScript. Using JavaScript to Uncheck Radio Button We can access the radio button in JavaScript using id, tag, name or other ways. After that, we can uncheck the radio button's ...
Read More