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
Javascript Articles
Page 309 of 534
How to get the list of document properties which can be accessed using W3C DOM?
The Document Object Model (DOM) provides several key properties that allow you to access and manipulate different parts of an HTML document. These properties are standardized by the W3C and are available across all modern browsers. Core Document Properties Here are the essential document properties you can access using the W3C DOM: Property Description & Example ...
Read MoreSubtract two Sets in Javascript
Set subtraction (difference) removes all elements from the first set that exist in the second set. JavaScript doesn't provide a built-in difference method, but we can create one using forEach or modern Set methods. Using forEach Method We can create a static method to subtract one Set from another: Set.difference = function(s1, s2) { if (!(s1 instanceof Set) || !(s2 instanceof Set)) { console.log("The given objects are not of type Set"); return null; ...
Read MoreHow to get the innerHTML of a cell with JavaScript DOM?
In this tutorial, we will learn how to get the innerHTML of a cell with JavaScript DOM. The innerHTML property allows us to access the HTML content inside table cells by first accessing the table structure through the DOM. We can manipulate the DOM (Document Object Model) easily using document.getElementById(). This method returns the element object that represents the element whose id is specified in the parameter. Since every element's id is unique, we can easily access specific table elements and then use the innerHTML property to retrieve the content of table cells. Using Table Cells Collection ...
Read MoreHow can I simplify the usage of Regular Expressions with JavaScript?
In this tutorial, we will learn to simplify the use of regular expressions in JavaScript. Regular expressions, also called Regex or RegExp, are sequences of characters that define search patterns. They can be simple or complex and work across many programming languages. Let's understand the need for regular expressions with a practical example. Why Should We Use Regular Expressions? Suppose you're developing an application that collects user emails. Users can enter anything in the input field, potentially creating spam records in your database. You need to validate emails before form submission. To validate an email, you ...
Read MoreWith JavaScript DOM delete rows in a table?
To delete rows in a table in JavaScript, use the DOM deleteRow() method. This method removes a row from a table by specifying its index position. Syntax table.deleteRow(index) Parameters The index parameter specifies which row to delete (0-based indexing). Use -1 to delete the last row. Example: Delete Rows One by One The following example shows how to delete table rows. Each click removes the first row: function deleteFirstRow() { ...
Read MoreAdd elements to a Dictionary in Javascript
In JavaScript, there are multiple ways to add elements to a dictionary-like structure. You can use plain objects, custom dictionary classes, or the ES6 Map object. Using Plain Objects The simplest approach is using JavaScript objects as dictionaries. You can add key-value pairs using bracket notation or dot notation: const dictionary = {}; // Using bracket notation dictionary["key1"] = "value1"; dictionary["key2"] = "value2"; // Using dot notation (for valid identifiers) dictionary.key3 = "value3"; console.log(dictionary); { key1: 'value1', key2: 'value2', key3: 'value3' } Custom Dictionary Class You can ...
Read MoreFind digits not between the brackets using JavaScript Regular Expressions?
In JavaScript, regular expressions with negated character classes [^0-9] are used to find characters that are NOT digits. The caret ^ inside square brackets creates a negated character class, matching any character except those specified. Regular expressions (RegExp) are powerful pattern-matching tools introduced in ES1 and supported by all modern browsers. They're commonly used for string validation, search operations, and text manipulation. Syntax The syntax for matching non-digits is: new RegExp("[^0-9]") // or simply /[^0-9]/ With modifiers for global matching: new RegExp("[^0-9]", "g") // or simply /[^0-9]/g ...
Read MoreClearing a Dictionary using Javascript
In JavaScript, dictionaries can be implemented using plain objects or ES6 Maps. Both approaches provide methods to clear all key-value pairs from the container. Clearing Custom Dictionary Objects For custom dictionary implementations using plain objects, you can create a clear() method that resets the container: clear() { this.container = {} } Example with Custom Dictionary class MyMap { constructor() { this.container = {}; } ...
Read MoreHow to check whether a value is a safe integer or not in JavaScript?
In this tutorial, we will learn to check whether a value is a safe integer or not in JavaScript. A safe integer in JavaScript is any number that can be accurately represented under the IEEE-754 double-precision format. Safe integers are all numbers between -(2^53 - 1) and (2^53 - 1) inclusive. JavaScript provides a built-in method for this check, but we can also implement custom logic. Here are the approaches we'll explore: Using the Number.isSafeInteger() Method (Recommended) Using Custom if-else Logic Using Number.isSafeInteger() Method The Number.isSafeInteger() ...
Read MoreFind the non-digit character with JavaScript Regular Expression
In this tutorial, we will learn to find non-digit characters using JavaScript regular expressions. The \D metacharacter matches any character that is not a digit (0-9), including letters, spaces, and special characters. RegExp is an object that specifies patterns used for search and replace operations on strings or input validation. RegExp was introduced in ES1 and is fully supported by all browsers. Syntax The syntax for matching non-digit characters is: new RegExp("\D") // Constructor syntax /\D/ // Literal syntax (recommended) ...
Read More