Articles on Trending Technologies

Technical articles with clear explanations and examples

Reversing strings with a twist in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 275 Views

We are required to write a JavaScript function that takes in a string str as the first argument and an integer num as the second argument. Our function should reverse the first num characters for every 2 * num characters counting from the start of the string. If there are less than num characters left, we have to reverse all of them. If there are less than 2 * num but greater than or equal to num characters, then we have to reverse the first num characters and leave the others as original. Example Input and Output ...

Read More

Longest string consisting of n consecutive strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 449 Views

Problem We are required to write a JavaScript function that takes in an array of strings. Our function should create combinations by combining all possible n consecutive strings in the array and return the longest such string that comes first. Example Following is the code − const arr = ["zone", "abigail", "theta", "form", "libe", "zas", "theta", "abigail"]; const num = 2; function longestConsec(strarr, k) { if (strarr.length == 0 || k > strarr.length || k longStr.length) { ...

Read More

Generating desired pairs within a range using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 283 Views

We are required to write a JavaScript function that takes in a number n. Our function should generate an array containing the pairs of integers [a, b] that satisfy the following conditions: 0

Read More

How to shift the baseline of individual characters in Text using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 423 Views

In this tutorial, we are going to learn how to shift the baseline of individual characters 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 shift the baseline of individual characters by using the deltaY property. Syntax new fabric.Text(text: String , { styles: { deltaY: ...

Read More

How to set the duration of animation on a Line using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 387 Views

In this tutorial, we are going to learn how to set the duration of animation on a Line 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 change the duration of animated text we use the duration property. Syntax ...

Read More

How to view array of a structure in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 453 Views

The easiest way to debug JavaScript code is using console.log(), which many developers use. Sometimes, we need to know an array's structure and stored values for debugging purposes. In this tutorial, we will learn to view the structure of arrays containing different data types. Various JavaScript methods allow us to examine the structure of arrays. For example, we can see if an array contains objects, nested arrays, strings, numbers, or Boolean values. Using the JSON.stringify() Method The JSON.stringify() method converts JavaScript objects into JSON strings. Since arrays are objects in JavaScript, we can use this method to ...

Read More

JavaScript Algorithm - Removing Negatives from the Array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 351 Views

Given an array X of multiple values (e.g. [-3, 5, 1, 3, 2, 10]), we need to write a function that removes any negative values from the array using only the pop() method without creating temporary arrays. The challenge is to modify the original array in-place, maintaining only positive numbers while using just the pop() method for removal. Algorithm Approach The algorithm works in two phases: Remove all negative values from the end of the array For remaining negatives, replace them with the last positive element and pop Complete Implementation function ...

Read More

Get max value per key in a JavaScript array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 517 Views

When working with arrays of objects in JavaScript, you might need to find the object with the maximum value for a specific property within each group. This is a common task when analyzing data grouped by categories. Consider this array of fruit data: const arr = [ {a:1, b:"apples"}, {a:3, b:"apples"}, {a:4, b:"apples"}, {a:1, b:"bananas"}, {a:3, b:"bananas"}, {a:5, b:"bananas"}, {a:6, b:"bananas"}, {a:3, b:"oranges"}, ...

Read More

How to test if a parameter is provided to a function in JavaScript?

Yaswanth Varma
Yaswanth Varma
Updated on 15-Mar-2026 4K+ Views

Testing if a parameter is provided to a function in JavaScript is an important part of writing effective code. It allows you to ensure that the arguments passed into your functions are valid and properly formatted for use within the function. In this article, we will discuss different methods for testing whether or not a parameter has been provided to a function in JavaScript. Let us understand the term "Parameter". A parameter is a named entity in a function definition that specifies an argument which the function can accept. It acts as a variable within the function and its ...

Read More

Trigger an event IMMEDIATELY on mouse click, not after I let go of the mouse - JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 333 Views

By default, the click event fires when you press and then release the mouse button. To trigger an event immediately when the mouse button is pressed down, use the mousedown event instead. The Difference Between click and mousedown The click event requires a complete click cycle (press down + release), while mousedown fires immediately when the button is pressed. Using mousedown Event Here's how to trigger an event immediately on mouse press: Mousedown Event Example ...

Read More
Showing 11881–11890 of 61,303 articles
Advertisements