Articles on Trending Technologies

Technical articles with clear explanations and examples

Comparing objects in JavaScript and return array of common keys having common values

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 836 Views

We are required to write a JavaScript function that takes in two objects. The function should return an array of all those common keys that have common values across both objects. Example The code for this will be − const obj1 = { a: true, b: false, c: "foo" }; const obj2 = { a: false, b: false, c: "foo" }; const compareObjects = (obj1 = {}, obj2 = {}) => { const common = Object.keys(obj1).filter(key => { if(obj1[key] === obj2[key] && obj2.hasOwnProperty(key)){ ...

Read More

Make an array of another array\'s duplicate values in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 1K+ Views

In JavaScript, finding duplicate values between two arrays is a common task. This article demonstrates how to create an array containing elements that exist in both arrays using built-in array methods. What is an Array in JavaScript? An array is an object that stores multiple elements in a single variable. Arrays in JavaScript are ordered collections that can hold any data type and provide methods like filter() and indexOf() for manipulation. const array = [201, 202, 405]; Understanding the Logic To find duplicate values between two arrays, we use the filter() method on ...

Read More

Given an array of integers return positives, whose equivalent negatives present in it in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 613 Views

In this problem, we need to find positive integers from an array that have their corresponding negative counterparts present in the same array. For example, if we have [1, -1, 2, -3, 4, -4], we should return [1, 4] since both 1 and 4 have their negatives (-1 and -4) in the array. Understanding the Problem Given an array of integers containing both positive and negative values, we need to identify positive numbers whose negative equivalents also exist in the array. For instance, in the array [7, ...

Read More

Squaring every digit of a number using split() in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 277 Views

We are required to write a JavaScript function that takes in a number as the first and the only argument. The function should then square every digit of the number, append them and yield the new number. For example − If the input number is − const num = 12349; Then the output should be − const output = 1491681; because '1' + '4' + '9' + '16' + '81' = 1491681 How It Works The solution uses split('') to convert each digit into an array element, then ...

Read More

Returning the expanded form of a number in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 430 Views

The expanded form of a number breaks down each digit into its place value. For example, 1234 becomes "1000 + 200 + 30 + 4". This is useful for teaching place value concepts and number decomposition. Problem We need to write a JavaScript function that takes a number and returns a string showing the expanded form, indicating the place value of each non-zero digit. Example const num = 56577; const expandedForm = (num = 0) => { const str = String(num); let res = ''; ...

Read More

Checking if decimals share at least two common 1 bits in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 168 Views

We need to write a JavaScript function that takes two numbers and returns true if they have at least two common 1 bits in their binary representations at the same positions. Problem Given two decimal numbers, we want to check if their binary representations share at least two 1 bits at the same index positions. For example, if we have numbers 10 (binary: 1010) and 15 (binary: 1111), we need to compare bit by bit and count matching 1s. Algorithm Approach The solution involves converting both numbers to binary strings, aligning them by removing extra leading ...

Read More

Forming the nearest time using current time in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 490 Views

In JavaScript, finding the nearest time using current time digits is a common algorithmic problem. We need to form the next closest time by reusing only the available digits from the input time. Problem Statement We are required to write a JavaScript function that takes in a string representing time in "HH:MM" format. The function should form the next closest time by reusing only the current digits, with no limit on how many times a digit can be reused. Example Input and Output For the input time '19:34': Input: '19:34' Available digits: 1, 9, ...

Read More

Logging in Node.js

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 472 Views

Logging is a very essential part in any application whether it is made in Node.js or any other programming languages. Logging helps us to detect weird behaviours of an application along with real-time errors and exceptions. One should definitely put logical logs in their application. These logs help the user to identify any mistakes and resolve it on urgent basis. There are 5 different log levels which are present at the moment with the user. These log levels are used to define different kinds of logs and helps the user to identify different scenarios. The log levels must be ...

Read More

Difference between addEventListener and on-click in JavaScript

Mayank Agarwal
Mayank Agarwal
Updated on 15-Mar-2026 1K+ Views

The addEventListener and the onclick event both listen for an event. Both these event methods record an event and execute a function based on that event whenever a button is clicked. Though there is a difference between how both these events work. In this article, we are going to explore the differences between the addEventListener and the onclick function in JavaScript. addEventListener Method The addEventListener method uses an event handler to attach it to the specified element. This method is more flexible and allows multiple event listeners on the same element. Syntax element.addEventListener(event, listener, ...

Read More

How to set the opacity of Triangle using FabricJS?

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

In this tutorial, we are going to learn how to set the opacity of Triangle using FabricJS. Triangle is one of the various shapes provided by FabricJS. In order to create a triangle, we will have to create an instance of fabric.Triangle class and add it to the canvas. We can customize a triangle object by adding a fill colour to it, eliminate its borders or even make changes in its dimensions. Similarly we can also change its opacity by using the opacity property. Syntax new fabric.Triangle({ opacity: Number }: Object) Parameters ...

Read More
Showing 15551–15560 of 61,297 articles
Advertisements