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
Masking email to hide it in JavaScript
It is a common practice that when websites display anyone's private email address they often mask it in order to maintain privacy. For example, if someone's email address is: const email = 'ramkumar@example.com'; It is displayed like this: r...r@example.com We need to write a JavaScript function that takes an email string and returns the masked email for that string. Basic Email Masking Function Here's a simple approach that masks the username part of the email: const email = 'ramkumar@example.com'; const maskEmail = (email = '') => ...
Read MoreFinding the missing number between two arrays of literals in JavaScript
Finding the missing number between two arrays is a common programming problem where one array is a shuffled version of another with exactly one element removed. Problem Statement We need to write a JavaScript function that takes two arrays: arr1 (original) and arr2 (shuffled duplicate with one missing element). The function should identify and return the missing element. Example const arr1 = [6, 1, 3, 6, 8, 2]; const arr2 = [3, 6, 6, 1, 2]; const findMissing = (arr1 = [], arr2 = []) => { const obj = ...
Read MoreSorting 2-D array of strings and finding the diagonal element using JavaScript
Problem We are required to write a JavaScript function that takes in an array of n strings. Each string in the array consists of exactly n characters. Our function should first sort the array in alphabetical order, then return the string formed by the characters present at the principal diagonal starting from the top left corner. Understanding the Process The solution involves two main steps: Sort the array of strings alphabetically Extract diagonal characters where row index equals column index (i === j) Example ...
Read Moreprocess.env() Method in Node.js
The process.env property in Node.js provides access to environment variables. It returns an object containing all environment variables available to the current process, making it essential for configuration management in Node.js applications. Syntax process.env Note: process.env is a property, not a method, so it doesn't require parentheses. Parameters process.env is a read-only object that doesn't accept parameters. It automatically contains all environment variables from the system where the Node.js process is running. Example: Accessing All Environment Variables Create a file named env.js and run it using: node env.js ...
Read MoreHow to use JavaScript to replace a portion of string with another value?
In this article, we are going to explore replacing a portion of a string with another value using JavaScript. We can replace string parts in multiple ways. Below are some common methods − replace() method split() and join() methods replaceAll() method Let's discuss the above methods in detail. Using replace() Method The replace() method is an inbuilt JavaScript method that replaces the first occurrence of a substring or regular expression pattern with a new value. The original string remains unchanged. Syntax ...
Read MoreHow to disable the centered scaling of Rectangle using FabricJS?
In this tutorial, we are going to learn how to disable the centered scaling 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. When being scaled via controls, assigning a true value to the centeredScaling property, uses the center as the object's origin of transformation. Syntax new fabric.Rect({ centeredScaling: Boolean }: Object) Parameters Options (optional) − ...
Read MoreHow to set the baseline of superscript with Text using FabricJS?
In this tutorial, we are going to learn how to set the baseline of superscript with 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. We can also use the superscript property where we can specify its baseline. Syntax new fabric.Text(text: String , { superscript : {"size": Number, "baseline": Number}: ...
Read MoreDisplay selected checkboxes on another page using JavaScript?
In this article, you will learn how to pass selected checkbox values from one page to another using JavaScript and localStorage. Checkboxes allow users to select multiple values, unlike radio buttons which only allow single selection. When a checkbox is checked, it represents a "true" value indicating user selection. Basic Checkbox Example Example checkbox This creates a simple checkbox that shows an alert when clicked. Getting Checkbox Values on Same Page First, let's see how to collect checked values within the same ...
Read MoreHow to validate if an element in an array is repeated? - JavaScript
We are required to write a JavaScript function that takes in two arguments: An Array, say arr, of literals that may contain some repeating elements. A number, say limit. The function should validate that no element of the array is repeated more than limit number of times. If any element is repeated more than the limit the function should return false, true otherwise. Using Object to Count Occurrences The most efficient approach is to use an object to count each element's occurrences, then check if any count exceeds ...
Read MoreExcluding extreme elements from average calculation in JavaScript
We need to write a JavaScript function that calculates the average of array elements while excluding the smallest and largest values. This is useful when you want to remove outliers from statistical calculations. Problem Statement Given an array of numbers, calculate the average excluding the minimum and maximum values. This helps eliminate extreme values that might skew the results. Example Let's implement a function that finds the excluded average: const arr = [5, 3, 5, 6, 12, 5, 65, 3, 2]; const findExcludedAverage = arr => { const creds ...
Read More