Articles on Trending Technologies

Technical articles with clear explanations and examples

How to return the background color of an element with JavaScript DOM?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 4K+ Views

In this tutorial, we will explore how to get and set the background color of an element using JavaScript DOM. The style.backgroundColor property allows us to both retrieve and modify background colors dynamically. Browser Support Chrome Browser − Version 1.0 and above. Edge Browser − Version 12 and above. Internet Explorer − Version 4.0 and above. Firefox Browser − Version 1.0 and above. Safari Browser − Version 1.0 and above. Opera Browser − Version 3.5 and above. Syntax ...

Read More

Value of the class attribute node of an element in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 447 Views

JavaScript provides the getAttributeNode() method to retrieve the attribute node of an element as an attribute object. This method returns the attribute node with the specified name, or null if the attribute doesn't exist. Syntax element.getAttributeNode(attributename); It returns the attribute object representing the specified attribute node. To get the actual value, use the value property of the returned object. Example: Getting Class Attribute Value In this example, we have two heading tags with different classes. We'll use getAttributeNode() to retrieve the class attribute and display its value. ...

Read More

Low level difference between Slice and Splice methods in Javascript

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 483 Views

The slice() and splice() methods are often confused due to their similar names, but they behave very differently. Understanding their key differences is crucial for array manipulation in JavaScript. Key Differences splice() modifies the original array by adding, removing, or replacing elements and returns an array of removed items. slice() creates a shallow copy of a portion of the array without modifying the original and returns the extracted elements. Syntax Comparison // splice syntax array.splice(startIndex, deleteCount, item1, item2, ...) // slice syntax array.slice(startIndex, endIndex) Example: Demonstrating the Difference ...

Read More

How to create a URL object using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 559 Views

The URL object in JavaScript provides a convenient way to parse and manipulate URLs. It extracts components like protocol, host, pathname, and search parameters from URL strings. Syntax let url = new URL(urlString); let url = new URL(urlString, baseURL); Parameters urlString - The URL string to parse baseURL - (Optional) Base URL for relative URLs Example URL Object Example body { ...

Read More

Changing an array in place using splice() JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 235 Views

The splice() method allows you to modify arrays in place by removing, adding, or replacing elements. This article demonstrates how to use splice() to remove duplicate elements that exceed a specified count limit. The Problem We need to write a function that takes an array and a number n, then removes elements that appear more than n times while preserving the order of remaining elements. Solution Using splice() We'll track element counts using a hashmap and use splice() to remove excess occurrences during iteration: const arr = [7, 26, 21, 41, 43, 2, 26, ...

Read More

Creating an associative array in JavaScript with push()?

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

An associative array in JavaScript is essentially an object that uses string keys to store arrays of values. You can create this structure by combining forEach() loops with the push() method to group related data. Example: Grouping Students by ID Here's how to create an associative array that groups student names by their student ID: var studentDetails = [ { studentId: 1, studentName: "John" }, { ...

Read More

Count appearances of a string in another - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 181 Views

We are required to write a JavaScript function that takes in two strings and returns the count of the number of times the first string appears in the second string. Let's say our string is: const main = 'This is the is main is string'; We have to find the appearance of the below string in the above "main" string: const sub = 'is'; Using Regular Expression with replace() Let's write the code for this function using a regular expression approach: const main = 'This is the is ...

Read More

How can I show a euro or other HTML entity in JavaScript alert windows?

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

This tutorial will teach us to show a euro or other HTML entities in JavaScript alert windows. JavaScript provides three types of pop-up windows: Alert box, Confirm box, and Prompt box. The alert box displays information to users, such as welcome messages or notifications. The confirm box shows confirmation messages and returns true/false based on user choice. The prompt box collects input from users through a pop-up interface. Default JavaScript alert boxes only display plain text, so we need special techniques to show currency symbols and other HTML entities. We can use Unicode escape sequences, decimal codes, or ...

Read More

What is the importance of _.initial() function in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 555 Views

The _.initial() function is part of the Underscore.js library that returns all elements of an array except the last n elements. It's useful for removing elements from the end of an array without modifying the original array. Syntax _.initial(array, n); Parameters array - The input array from which to extract elements. n (optional) - Number of elements to exclude from the end. Default is 1. Return Value Returns a new array containing all elements except the last n elements. Example: Basic Usage ...

Read More

What is JavaScript's highest integer value that a Number can go to without losing precision?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 23K+ Views

JavaScript's highest integer value that maintains precision is Number.MAX_SAFE_INTEGER, which equals 9, 007, 199, 254, 740, 991 (253 - 1). This limitation exists because JavaScript uses IEEE 754 double-precision floating-point format for numbers. Understanding Safe Integer Range JavaScript can only properly represent integers between -(253 - 1) and 253 - 1. The term "safe" means you can accurately represent, compare, and perform arithmetic operations on integers within this range. ...

Read More
Showing 18581–18590 of 61,297 articles
Advertisements