Articles on Trending Technologies

Technical articles with clear explanations and examples

Removing the second number of the pair that add up to a target in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 176 Views

Problem We need to write a JavaScript function that takes an array of numbers and a target sum. The function should remove the second number from any consecutive pair of numbers that add up to the target. Example Let's see how this works with a practical example: const arr = [1, 2, 3, 4, 5]; const target = 3; const removeSecond = (arr = [], target = 1) => { const res = [arr[0]]; for(let i = 1; i < arr.length; i++){ ...

Read More

How to create a cloned image object using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 1K+ Views

In this tutorial, we are going to show how you can create a cloned image object using FabricJS. 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 create a cloned image object, we use the cloneAsImage method. Syntax cloneAsImage(callback: function, options: Object): fabric.Object Parameters callback (optional) − This parameter is a function which is invoked with a cloned image instance as ...

Read More

How to Change the Time Interval of setinterval() Method at RunTime using JavaScript ?

Abhishek
Abhishek
Updated on 15-Mar-2026 3K+ Views

The setInterval() method is used to call a particular block of code repeatedly after a specific time interval. It accepts two parameters: the function to execute and the time interval in milliseconds. Sometimes you need to change this interval dynamically during runtime for irregular or variable timing patterns. JavaScript provides two main approaches to change the time interval of setInterval() at runtime: Using the clearInterval() method Using the setTimeout() method Let us understand both approaches with practical examples. Using the clearInterval() Method The clearInterval() method stops a ...

Read More

How to create a third object from two objects using the key values in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 256 Views

In JavaScript, you can create a third object from two objects by mapping key values between them. This is useful when you have one object containing arrays of keys and another object with corresponding values. Problem Statement Given two objects where the first contains arrays of keys and the second contains key-value pairs, we need to calculate totals for each category: const obj1 = { positive: ['happy', 'excited', 'joyful'], negative: ['depressed', 'sad', 'unhappy'] }; const obj2 = { happy: 6, excited: 1, unhappy: 3 }; ...

Read More

Return the greatest possible product of n numbers from the array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 164 Views

We are required to write a JavaScript function that takes in an array of Numbers as the first argument and a number, say n, as the second argument. Our function should calculate and return the greatest possible product of n numbers from the array. Problem Analysis To find the maximum product of n numbers, we need to consider both positive and negative numbers. Two negative numbers multiplied together give a positive result, so the strategy involves: Sorting the array to identify the largest and smallest values Choosing ...

Read More

Converting 12 hour Format Time to 24 hour Format in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 10K+ Views

Converting 12 hour format time to 24 hour format in JavaScript can be easily achieved using various approaches which we will be discussing in this article. For conversion from 12 hour to 24 hour format we check for the modifier (AM or PM). Depending on the modifier we convert the time formats. In this article, we have specified a time at the beginning in 12 hour format. Our task is to convert 12 hour format time to 24 hour format in JavaScript. Approaches to Convert 12-hour Format to 24-hour Here is a list of approaches to convert ...

Read More

Finding the immediate bigger number formed with the same digits in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 371 Views

We need to write a JavaScript function that takes a number and rearranges its digits to form the smallest number that is just bigger than the input number using the same digits. For instance, if the input number is 112, the output should be 121. If no bigger number can be formed (like 321), we return -1. Algorithm Approach The brute force approach involves: Find the maximum possible number by sorting digits in descending order Check each number from input+1 to maximum Return the first number that uses the same digits Example Implementation ...

Read More

How to create a JSON representation of an Image object using FabricJS?

Rahul Gurung
Rahul Gurung
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we are going to learn how to create a JSON representation of an Image object using FabricJS. 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 create a JSON representation of an Image object, we use the toJSON method. Syntax toJSON(propertiesToInclude: Array): Object Parameters propertiesToInclude − This parameter accepts an Array which contains any properties we might want ...

Read More

Sum of distinct elements of an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 283 Views

Suppose, we have an array of numbers like this − const arr = [1, 5, 2, 1, 2, 3, 4, 5, 7, 8, 7, 1]; We are required to write a JavaScript function that takes in one such array and counts the sum of all distinct elements of the array. For example: The output for the array mentioned above will be − 30 Method 1: Using lastIndexOf() and indexOf() This approach checks if the current index is the last occurrence of each element, ensuring we count each distinct element ...

Read More

Absolute difference of Number arrays in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 513 Views

In JavaScript, calculating the absolute difference between corresponding elements of two arrays is a common operation. This involves subtracting elements at the same index positions and taking the absolute value of the result. Suppose we have two arrays like these: const arr1 = [1, 2, 3, 4, 5, 6]; const arr2 = [9, 8, 7, 5, 8, 3]; We need to create a function that returns an array of absolute differences between corresponding elements. For these arrays, the expected output should be: [8, 6, 4, 1, 3, 3] Using For Loop ...

Read More
Showing 14461–14470 of 61,297 articles
Advertisements