Articles on Trending Technologies

Technical articles with clear explanations and examples

How to format a rounded number to N decimals using JavaScript?

Anvi Jain
Anvi Jain
Updated on 15-Mar-2026 529 Views

Use the toFixed() method to format a rounded number to N decimals. The toFixed() method formats a number with a specific number of digits to the right of the decimal point and returns a string representation. Syntax number.toFixed(digits) Parameters digits (optional): An integer specifying the number of digits after the decimal point. Must be in the range 0-100. Default is 0. Return Value Returns a string representation of the number with the specified number of decimal places. Example Here's how to format numbers to different decimal places: ...

Read More

How to randomize (shuffle) a JavaScript array?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 2K+ Views

In this tutorial, we will learn different methods to randomize or shuffle a JavaScript array. Shuffling arrays is a common requirement in programming, useful for games, random sampling, or creating unpredictable sequences. Using the Fisher-Yates Algorithm The Fisher-Yates algorithm is the most reliable method for shuffling arrays. It iterates through the array from the last index to the first, swapping each element with a randomly selected element from the remaining unshuffled portion. Syntax for (var i = arr.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + ...

Read More

Match any string containing a sequence of two to three p's.

Akshaya Akki
Akshaya Akki
Updated on 15-Mar-2026 162 Views

To match any string containing a sequence of two to three p's with JavaScript RegExp, use the p{2, 3} quantifier. This pattern matches exactly 2 or 3 consecutive occurrences of the letter "p". Syntax /p{2, 3}/flags Where {2, 3} specifies the minimum (2) and maximum (3) number of consecutive p's to match. Example: Matching 2-3 Consecutive p's JavaScript Regular Expression var str = "apple pepper hippopotamus p programming"; ...

Read More

How to set whether the image-border should be repeated, rounded or stretched with JavaScript?

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

This tutorial will teach us to set whether the border image should be repeated, rounded, or stretched with JavaScript. Use the borderImageRepeat property to set whether the image-border is to be repeated, rounded, or stretched. Borders are used to decorate or focus an element. You can define its width, color, and type of border. Various styles can be applied to the borders. But, these borders are without any special effects or any other designs. Using the border-image property, we can set an image as a border of an element. It does not look like a line. It will ...

Read More

canvas.style.display = "block" not working in HTML5

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 331 Views

When working with HTML5 canvas elements, you might encounter issues where setting canvas.style.display = "block" doesn't work as expected. This usually happens due to timing issues, incorrect element selection, or CSS conflicts. Common Problem The most frequent issue occurs when trying to modify the canvas display style before the DOM is fully loaded or when the canvas element reference is incorrect. Show Canvas function showCanvas() { let canvas = document.getElementById("myCanvas"); canvas.style.display = "block"; console.log("Canvas display set to:", canvas.style.display); } ...

Read More

DataView.byteOffset property in JavaScript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 128 Views

The byteOffset property of the DataView represents the offset (in bytes) from the start of the underlying ArrayBuffer where the DataView begins. Syntax Its syntax is as follows: dataView.byteOffset Return Value Returns a number representing the byte offset of the DataView from the beginning of its ArrayBuffer. Example 1: Basic byteOffset When creating a DataView without specifying an offset, the byteOffset property returns 0: JavaScript DataView byteOffset Example ...

Read More

How can you detect the version of a browser using Javascript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 5K+ Views

In this article, we are going to discuss how to detect the version of a browser using JavaScript. These days, most browsers are JavaScript-enabled. But still, there are some browsers that don't support JavaScript; or, some versions of some browsers don't support certain features of JavaScript. Therefore, in certain instances, there is a need to know the details of the client's web browser so that the applications can deliver appropriate content. Detecting the Version of a Browser You can detect the details of the current browser using navigator.appName and navigator.appVersion properties. To detect the version ...

Read More

Lambdas with Arrow Functions in JavaScriptLambdas with Arrow Functions in JavaScript

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

Lambda functions in JavaScript are small anonymous functions that can take parameters and return values. Arrow functions provide a concise way to write lambda functions and are commonly used for functional programming operations like map(), filter(), and reduce(). Syntax // Single parameter (parentheses optional) const lambda1 = x => x * 2; // Multiple parameters const lambda2 = (x, y) => x + y; // No parameters const lambda3 = () => "Hello World"; // Multiple statements (requires curly braces and return) const lambda4 = x => { const result ...

Read More

Filter an object based on an array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 838 Views

Let's say we have an array and an object like this: const arr = ['a', 'd', 'f']; const obj = { "a": 5, "b": 8, "c": 4, "d": 1, "e": 9, "f": 2, "g": 7 }; We are required to write a function that takes in the object and the array and filter away all the object properties that are not an element of the array. So, the output should only contain 3 properties, namely: "a", "d" and "f". Method 1: ...

Read More

Object difference in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 189 Views

In JavaScript, finding the difference between two objects means identifying keys that exist in the first object but not in the second. This is useful for comparing data structures, tracking changes, or filtering object properties. Problem Statement We need to write a JavaScript function that takes two objects (possibly nested) and returns a new object containing only the key-value pairs that exist in the first object but are missing from the second object. Basic Implementation Here's a function that compares two objects and returns the difference: const obj1 = { "firstName": ...

Read More
Showing 17051–17060 of 61,297 articles
Advertisements