Articles on Trending Technologies

Technical articles with clear explanations and examples

Constructing a nested JSON object in JavaScript

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

In JavaScript, we often need to construct nested objects from structured data. This article demonstrates how to build a nested JSON object from a string containing paired characters. Problem Statement Given a string with characters in pairs, we need to construct a nested object where each pair becomes a code property, and each level has a sub-object for the next pair. Input string: const str = "AABBCCDDEE"; Expected output structure: const obj = { code: "AA", sub: { ...

Read More

String to binary in JavaScript

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

Converting strings to binary representation is a common task in JavaScript programming. This involves converting each character to its ASCII code and then to binary format. For example, if we have: const str = 'Hello World'; The binary output should be: 1001000 1100101 1101100 1101100 1101111 100000 1010111 1101111 1110010 1101100 1100100 How It Works The conversion process involves three steps: Split the string into individual characters Get the ASCII code of each character using charCodeAt() ...

Read More

Counting specific digits used in squares of numbers using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 410 Views

We need to write a JavaScript function that takes an integer n (n >= 0) and a digit d (0

Read More

How to print colored text in the console using JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 3K+ Views

In this article, we will learn how to add colors to the text and print them in the console window of JavaScript. In the original, all the data printed in the console is of black color no other color is reflected in the console but here we are going to add some special characters with text to make our console window look more colorful. There are some special codes that help change in color of the output in the console window and these codes are known as ANSI escape codes. By adding these codes in the console.log() method we ...

Read More

How to set default values when destructuring an object in JavaScript?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 6K+ Views

The array and object destructuring feature was introduced in the ES6 version of JavaScript. The destructuring of the array and object allows us to store its values in a separate variable. After that, we can use that variable to access the value of the particular property of the object. The main thing we need to focus on while destructuring the array object is the default values. For example, we have added the property3 variable in the destructuring object, but if the object doesn't contain the property3, destructuring sets the undefined value to the property3 variable. Users can follow ...

Read More

Finding sum of every nth element of array in JavaScript

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

We are required to write a JavaScript function that takes in an array of numbers and returns the cumulative sum of every number present at the index that is a multiple of n from the array. Understanding the Problem When we say "every nth element", we mean elements at indices 0, n, 2n, 3n, and so on. For example, if n=3, we sum elements at indices 0, 3, 6, 9, etc. Example Let's find the sum of every 3rd element from an array: const arr = [5, 3, 5, 6, 12, 5, 65, 3, ...

Read More

Checking the equality of array elements (sequence dependent) in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 409 Views

In this article, we'll learn how to check the equality of array elements in a sequence-dependent manner. This means comparing arrays element by element at the same index positions to find matching values or count similarities. Input-Output Scenario Let's look at how sequence-dependent comparison works with two arrays: Array1 = [2, 5, 6, 7, 9, 0]; Array2 = [3, 5, 0, 8, 9, 4]; Output = [5, 9] In the above example, elements 5 and 9 appear at the same index positions (index 1 and 4) in both arrays, making them sequence-dependent matches. ...

Read More

Sorting array according to increasing frequency of elements in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 402 Views

We are required to write a JavaScript function that takes in an array of literals as the first and the only argument. The array is likely to contain many repeating values. Our function should sort the array such that the values that are unique or that have the least frequency are placed before the ones that have the most. For example − If the input array is − const arr = [4, 7, 3, 5, 5, 4, 7, 9, 2, 1, 5, 7, 5, 5, 9]; Then the output array should be − ...

Read More

Finding length, width and height of the sheet required to cover some area using JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 331 Views

Problem Statement We need to write a JavaScript function that calculates the number of wallpaper sheets required to cover a room's walls. Given the room's length, width, and height, we must determine how many sheets are needed when each sheet has dimensions of 0.52 units width and 10 units length. The function should return 15% more sheets than the calculated requirement to account for waste and cutting. Understanding the Calculation The total wall area of a rectangular room is calculated using the formula: 2 × (length + width) × height. This covers all four walls, excluding ...

Read More

How to check the current runtime environment is a browser in JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 3K+ Views

A runtime environment is an environment where your code executes. It determines what global objects your code can access and affects its behavior. JavaScript can run in different environments like Node.js, Service Workers, or web browsers. Each browser comes with a JavaScript engine, so you can run JavaScript directly without additional software. Sometimes you need to detect which runtime environment your code is running in to ensure compatibility and use environment-specific features appropriately. Basic Browser Detection To check if the runtime environment is a browser, we can test for the presence of the global window object, which ...

Read More
Showing 16381–16390 of 61,297 articles
Advertisements