Articles on Trending Technologies

Technical articles with clear explanations and examples

How to create a countdown timer with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 750 Views

A countdown timer in JavaScript uses setInterval() to update the display every second by calculating the time difference between a target date and the current time. How It Works The countdown timer works by: Setting a target date in the future Calculating the time difference every second Converting milliseconds to days, hours, minutes, and seconds Updating the display and stopping when time expires Complete Example body { ...

Read More

Object.fromEntries() method in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 210 Views

The Object.fromEntries() method in JavaScript converts an iterable of key-value pairs (like arrays or Maps) into an object. It's the reverse operation of Object.entries(). Syntax Object.fromEntries(iterable) Parameters iterable: An iterable containing key-value pairs, such as an array of arrays or a Map. Return Value Returns a new object with properties derived from the key-value pairs in the iterable. Example: Converting Array of Arrays Object.fromEntries() Example Object.fromEntries() ...

Read More

Check if values of two arrays are the same/equal in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 709 Views

We have two arrays of numbers, let's say − [2, 4, 6, 7, 1] [4, 1, 7, 6, 2] Assume, we have to write a function that returns a boolean based on the fact whether or not they contain the same elements irrespective of their order. For example − [2, 4, 6, 7, 1] and [4, 1, 7, 6, 2] should yield true because they have the same elements but ordered differently. Method 1: Using includes() and Length Check This approach checks if both arrays have the same length and every element from ...

Read More

How to make my textfield empty after button click in JavaScript?

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

To clear a text field after a button click in JavaScript, you can use the onclick event with document.getElementById().value = '' to reset the input field's value to an empty string. Syntax document.getElementById("fieldId").value = ''; Example Clear Text Field Example Clear Text function clearTextField() { ...

Read More

Finding unlike number in an array - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 258 Views

We are required to write a JavaScript function that takes in an array of literals containing all similar elements but one. Our function should return the unlike number. The Problem Given an array where all elements are the same except one, we need to identify and return the unique element. This is a common programming challenge that can be solved efficiently using different approaches. Method 1: Using Frequency Count The most straightforward approach is to count the frequency of each element and return the one that appears only once. const arr = [2, 4, ...

Read More

How exactly does work?

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

The defer attribute tells the browser to download the script while parsing HTML but delay execution until the DOM is fully built. It only works with external scripts and maintains execution order. How defer Works HTML Parsing Script Download Script Execution 1. HTML parsing continues while script downloads 2. Script waits until DOM is complete 3. Scripts execute in document order ...

Read More

How do you access the matched groups in a JavaScript regular expression?

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

This tutorial will teach us to access the matched groups in JavaScript regular expression. The regular expression is the sequence of the character, also called the RegEx, and it is useful to match specific patterns in the string. There can be more than one match for the specific pattern in the string. To get the occurrence of all matches, we have explained the different methods below in this tutorial. We will also see the various usage of the regular expression in this article. Use the 'g' flag while creating the Regex When we add 'g' as ...

Read More

What is the usage of the onbeforeunload event in JavaScript?

Sravani S
Sravani S
Updated on 15-Mar-2026 227 Views

The onbeforeunload event triggers when a user attempts to leave the page, such as closing the tab, refreshing, or navigating to another URL. It's commonly used to warn users about unsaved changes. Syntax window.onbeforeunload = function(event) { // Return a string to show confirmation dialog return "Your message here"; }; // Or using addEventListener window.addEventListener('beforeunload', function(event) { event.preventDefault(); event.returnValue = ''; }); Example: Basic Implementation onbeforeunload Example ...

Read More

How to set whether the style of the font is normal, italic or oblique with JavaScript?

Jai Janardhan
Jai Janardhan
Updated on 15-Mar-2026 190 Views

To set the style of the font in JavaScript, use the fontStyle property. This property accepts three values: normal, italic, and oblique. Syntax element.style.fontStyle = "normal" | "italic" | "oblique"; Example: Setting Font Style to Italic This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This is Demo Text. This ...

Read More

Working with tag in HTML5

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 335 Views

The tag in HTML5 SVG allows you to create multi-sided shapes by defining a series of connected straight lines. It's perfect for creating geometric shapes like triangles, stars, and other polygonal figures. Syntax Key Attributes The points attribute defines the polygon's vertices as coordinate pairs (x, y), separated by spaces or commas. Other common attributes include fill, stroke, and stroke-width. Example: Creating an SVG Star ...

Read More
Showing 17841–17850 of 61,297 articles
Advertisements