Javascript Articles

Page 308 of 534

Clearing the elements of the PriorityQueue using Javascript

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

In JavaScript, clearing a PriorityQueue can be accomplished by resetting the container array that holds the queue elements. This is a simple but effective approach. Clear Method Implementation The most straightforward way to clear a PriorityQueue is to reassign the container to an empty array: clear() { this.container = []; } Complete Example Here's a working example demonstrating the clear functionality with a basic PriorityQueue implementation: class PriorityQueue { constructor() { this.container = []; ...

Read More

How can I access document properties using Legacy DOM method in JavaScript?

Srinivas Gorla
Srinivas Gorla
Updated on 15-Mar-2026 247 Views

To access document properties using Legacy DOM methods in JavaScript, you can use various built-in properties and collections that provide information about the document structure and content. Common Legacy DOM Properties The Legacy DOM provides several properties to access document information: document.title - Gets the document title document.URL - Gets the complete URL document.forms - Collection of all forms document.images - Collection of all images document.links - Collection of all links Example Document Title ...

Read More

Creating a Set using Javascript

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

In JavaScript, a Set is a collection of unique values. You can create sets using the native ES6 Set class or implement a custom set class. Let's explore both approaches. Creating Sets with ES6 Set Class The simplest way to create a set is using the built-in Set constructor: // Create empty set const set1 = new Set(); // Create set with initial values const set2 = new Set([1, 2, 5, 6]); console.log(set1); console.log(set2); Set(0) {} Set(4) { 1, 2, 5, 6 } Custom Set Implementation You can ...

Read More

How objects are organized in a web document? How is it arranged in a hierarchy?

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

The objects in a web document are organized in a hierarchical structure called the Document Object Model (DOM). This hierarchy represents the relationship between different elements and allows JavaScript to interact with web page components systematically. DOM Hierarchy Structure The DOM follows a tree-like structure where each object has a specific position and relationship with other objects: Window object − Top of the hierarchy. It represents the browser window and is the global object for all JavaScript operations. ...

Read More

What are the document methods supported by Legacy DOM?

Priya Pallavi
Priya Pallavi
Updated on 15-Mar-2026 177 Views

The Legacy DOM provided several document methods for manipulating document content. While most are deprecated in modern web development, understanding them helps with legacy code maintenance. Legacy DOM Document Methods Method Description & Usage clear() Deprecated - Erased document contents and returned nothing. Example: document.clear() close() Closes a document stream opened with open() method. Example: document.close() open() Deletes existing content and opens a stream for new content. Example: document.open() write() Inserts strings into the document during parsing or after open(). Example: document.write("Hello World") ...

Read More

Clearing the set using Javascript

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

In JavaScript, the clear() method removes all elements from a Set. For built-in Sets, you can use the native clear() method. For custom Set implementations, you reassign the container to an empty object. Using Built-in Set clear() Method const mySet = new Set(); mySet.add(1); mySet.add(2); mySet.add(5); console.log("Before clear:", mySet); mySet.clear(); console.log("After clear:", mySet); console.log("Size:", mySet.size); Before clear: Set(3) { 1, 2, 5 } After clear: Set(0) {} Size: 0 Custom Set Implementation For a custom Set class, the clear method reassigns the container to a new empty object: ...

Read More

What is the role of special characters in JavaScript Regular Expressions?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 336 Views

Special characters in JavaScript regular expressions are metacharacters that define patterns for matching text. These characters control how many times a character or group should appear and where it should be positioned within a string. Quantifiers Quantifiers specify how many times the preceding character or group should match: Character Description + Matches one or more occurrences of the preceding character * Matches zero or more occurrences of the preceding character ? Matches zero or one occurrence of the preceding character {n} Matches exactly n ...

Read More

Loop through a Set using Javascript

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

In JavaScript, you can loop through a Set using several methods. The most common approaches are using the forEach() method, for...of loop, or converting to an array. Using forEach() Method The forEach() method executes a provided function for each value in the Set: const mySet = new Set([1, 2, 5, 8]); mySet.forEach(value => { console.log(`Element is ${value}`); }); Element is 1 Element is 2 Element is 5 Element is 8 Using for...of Loop The for...of loop provides a cleaner syntax for iterating over Set values: ...

Read More

How to access document properties using W3C DOM method?

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

The W3C DOM (Document Object Model) provides standardized methods to access and manipulate HTML document properties. Unlike browser-specific approaches, W3C DOM methods work consistently across all modern browsers. Common W3C DOM Methods The most frequently used methods for accessing document properties include: getElementById() - Gets element by its ID attribute getElementsByTagName() - Gets elements by tag name getElementsByClassName() - Gets elements by class name querySelector() - Gets first element matching CSS selector Example: Accessing Document Properties Here's how to access various document properties using W3C DOM methods: ...

Read More

Adding two Sets in Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 3K+ Views

The operation of adding 2 sets is known as a union. You need to add every element from one set to another while checking for duplicates. JavaScript's built-in Set class doesn't include a union method, but we can implement it using several approaches. Method 1: Using Spread Operator (Recommended) The most concise way to combine two sets is using the spread operator: let setA = new Set([1, 2, 3, 4]); let setB = new Set([2, 3, 5, 6]); // Create union using spread operator let unionSet = new Set([...setA, ...setB]); console.log(unionSet); console.log("Size:", unionSet.size); ...

Read More
Showing 3071–3080 of 5,340 articles
« Prev 1 306 307 308 309 310 534 Next »
Advertisements