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
process.argv() Method in Node.js
The process.argv property returns an array containing command-line arguments passed when the Node.js process was launched. The first element is the path to the Node.js executable, and the second is the path to the JavaScript file being executed. Syntax process.argv Parameters process.argv is a property, not a method, so it doesn't take any parameters. It automatically captures all command-line arguments passed to the Node.js process. Basic Usage Example Create a file named argv.js and run it using the command node argv.js: // Node.js program to demonstrate the use of process.argv ...
Read MoreHow to Ping a Server using JavaScript?
A server ping can be defined as hitting a server and getting a response in return from that server. The idea is to send an echo message that will keep the health check and check whether the server is up and running or not. On sending a PING every server sends a PONG that shows that the server is active. Ping messages are sent by the ICMP (Internet Control Messaging Protocol). The lower the ping time the stronger the connection between the host and the server. JavaScript Limitations for True ICMP Ping JavaScript in web browsers cannot perform ...
Read MoreHow to create a Rectangle with progress cursor on hover over objects using FabricJS?
In this tutorial, we are going to create a Rectangle with a progress cursor on hover over objects using FabricJS. progress is one of the native cursor styles available which can be used in the FabricJS canvas too. FabricJS provides various types of cursors like default, all-scroll, crosshair, col-resize, row-resize, etc., that actually use the native cursor under the hood. The hoverCursor property sets the style of the cursor when hovered over a canvas object. Syntax new fabric.Rect({ hoverCursor: String }: Object) Parameters Options (optional) − This parameter is an ...
Read MoreHow to set the angle of rotation of a Text using FabricJS?
In this tutorial, we are going to set the angle of rotation of a 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. The angle property in FabricJS defines the angle of 2D rotation of an object. We also have the centeredRotation property that allows us to use the center point of a ...
Read MoreProduct of numbers present in a nested array in JavaScript
We are required to write a JavaScript function that takes in an array of nested arrays of Numbers and some falsy values (including 0) and some strings as well and the function should return the product of number values present in the nested array. If the array contains some 0s, we should ignore them as well. Example The code for this will be − const arr = [ 1, 2, null, [ 2, 5, null, undefined, false, 5, [ ...
Read MoreHow to detect and replace all the array elements in a string using RegExp in JavaScript?
In JavaScript, you can detect and replace all array elements in a string using regular expressions (RegExp). This technique is useful for text processing, content filtering, and dynamic string manipulation where you need to replace multiple values at once. Let's explore different methods to detect and replace all array elements in a string using RegExp in JavaScript. Using RegExp with join() Method The most efficient approach is to create a single regular expression pattern by joining array elements with the OR operator (|). Syntax new RegExp(array.join('|'), 'flags') Example: Basic Replacement ...
Read MoreHow to find inside an array of objects the object that holds the highest value in JavaScript?
Finding the object with the highest value in an array of objects is a common task in JavaScript. This example demonstrates how to find the student with the highest grade from an array of student objects. Sample Data Let's start with an array of student objects, where each student has a name and an array of grades: const arr = [ { name: "Student 1", grades: [ 65, 61, 67, 70 ] ...
Read MoreElements that appear twice in array in JavaScript
We are required to write a JavaScript function that takes in an array of literal values. Our function should pick all those values from the array that appear exactly twice in the array and return a new array of those elements. Basic Approach Using Helper Function The first approach uses a helper function to count occurrences of each element: const arr = [0, 1, 2, 2, 3, 3, 5]; const findAppearances = (arr, num) => { let count = 0; for(let i = 0; i < arr.length; ...
Read MoreFinding the common streak in two arrays in JavaScript
We are required to write a JavaScript function that takes in two arrays of literals, let's call them arr1 and arr2. The function should find the longest common streak of literals in the arrays. The function should finally return an array of those literals. For example − If the input arrays are − const arr1 = ['a', 'b', 'c', 'd', 'e']; const arr2 = ['k', 'j', 'b', 'c', 'd', 'w']; Then the output array should be − ['b', 'c', 'd'] Algorithm Overview This problem uses dynamic programming to ...
Read MoreCounting pairs with range sum in a limit in JavaScript
In JavaScript, counting pairs with range sum within a limit involves finding all possible subarrays whose sum falls within a specified range. This is a common array processing problem that requires careful handling of cumulative sums. Range Sum Range sum rangeSum(i, j) is defined as the sum of the elements in an array between indices i and j (i ≤ j), inclusive. Problem We are required to write a JavaScript function that takes in an array of Integers, arr, as the first argument and two numbers, lower and upper as the second and third element. ...
Read More