Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to return the background color of an element with JavaScript DOM?
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 MoreValue of the class attribute node of an element in JavaScript?
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 MoreLow level difference between Slice and Splice methods in Javascript
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 MoreHow to create a URL object using JavaScript?
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 MoreChanging an array in place using splice() JavaScript
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 MoreCreating an associative array in JavaScript with push()?
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 MoreCount appearances of a string in another - JavaScript
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 MoreHow can I show a euro or other HTML entity in JavaScript alert windows?
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 MoreWhat is the importance of _.initial() function in JavaScript?
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 MoreWhat is JavaScript's highest integer value that a Number can go to without losing precision?
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