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
Compare and fill arrays - JavaScript
We are required to write a function that compares two arrays and creates a third array filling that array with all the elements of the second array and filling null for all those elements that are present in the first array but misses out in the second array. For example − If the two arrays are − const arr1 = ['f', 'g', 'h']; const arr2 = ['f', 'h']; Then the output should be − const output = ['f', null, 'h']; Algorithm Approach The solution uses an offset variable to ...
Read MoreHow can I get H1 innerText in JavaScript without the innerText of its child?
Getting the inner text of an HTML element is a common task when developing web applications. In JavaScript, it can be done using the innerText property of the HTMLElement object. However, this only returns the text within that particular element and not any of its child elements. If you need to get just the H1 tag's innertext without including its child elements' innertext, then there are several ways to do so. This article will discuss some methods for getting an H1 tag's innertext in JavaScript without including its child elements' innertext. The rendered text content of a node, ...
Read MoreTrim and split string to form array in JavaScript
When working with comma-separated strings that contain unwanted whitespace, you need to trim spaces and split the string into an array. JavaScript provides multiple approaches to accomplish this task efficiently. Problem Statement Given a comma-separated string with irregular spacing: const str = "a, b, c, d , e"; console.log("Original string:", str); Original string: a, b, c, d , e We need to remove all whitespaces and split it into a clean array of elements. Method 1: Manual Space Removal This approach manually loops through the string to remove spaces ...
Read MoreMin window substring in JavaScript
We are required to write a JavaScript function that takes in two strings let's call them str1 and str2. The size of str1 is guaranteed to be greater than that of str2. We are required to find the smallest substring in str1 that contains all the characters contained in str2. For example − If the input strings are − const str1 = 'abcdefgh'; const str2 = 'gedcf'; Then the output should be − const output = 'cdefg'; because this the smallest consecutive substring of str1 that contains all characters ...
Read MoreFinding the nth power of array element present at nth index using JavaScript
We need to write a JavaScript function that takes an array of numbers and maps each element to its power based on its 0-based index position. For example, the element at index 0 is raised to power 0, the element at index 1 is raised to power 1, and so on. Problem Statement Create a function that transforms an input array where each element is raised to the power of its index position, then return the resulting array. Example Here's how to implement this using a traditional for loop: const arr = [5, 2, ...
Read Moresend(), sendStatus() and json() method in Node.js
In Express.js, the send(), sendStatus(), and json() methods are essential for sending responses to clients. The send() method sends data in string format, json() sends data in JSON format with proper headers, and sendStatus() sends HTTP status codes with default status messages. Prerequisites Node.js installed Basic understanding of Express.js Installation Install the Express module using npm: npm install express Understanding sendStatus() Method The sendStatus() method sends an HTTP status code along with its default message. Common status codes include 200 (OK), 404 (Not Found), 201 (Created), ...
Read MoreHow to search a string for a pattern in JavaScript?
Searching strings for specific patterns is a common task in JavaScript. Strings are data types and are represented as a sequence of characters. Searching patterns means verifying the presence of a specific pattern in a given string. A pattern would be a specific word, specific characters, and so on. JavaScript offers several powerful methods for pattern matching, such as inbuilt string methods and regular expressions. This article will guide you on how to search strings for specific patterns in JavaScript. Table of contents Searching strings for specific patterns in JavaScript can be done in the following ways: ...
Read MoreHow to flip a Rectangle vertically using FabricJS?
In this tutorial, we are going to learn how we can flip a Rectangle object vertically 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 flip a rectangle object vertically using the flipY property. Syntax new fabric.Rect({ flipY: Boolean }: Object) Parameters Options (optional) − This parameter is an Object which provides additional customizations to our ...
Read MoreFabricJS – How to set a multiplier to scale by in the URL string of a Line object?
In this tutorial, we are going to learn about how to set a multiplier to scale by in the URL string of Line object using 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. In order to set a multiplier to scale by in the URL ...
Read MoreHow to set full-screen iframe with height 100% in JavaScript?
Setting an iframe to full-screen with 100% height is a common requirement in web development. This can be achieved using JavaScript's style.height property along with additional CSS properties to create a proper full-screen experience. The style.height property sets or returns the height of an HTML element as a string value. When combined with other style properties like position: fixed and proper positioning, it creates a true full-screen iframe overlay. Syntax element.style.height = "100%"; element.style.width = "100%"; element.style.position = "fixed"; element.style.top = "0"; element.style.left = "0"; element.style.zIndex = "9999"; Parameters ...
Read More