Samual Sam

Samual Sam

1,507 Articles Published

Articles by Samual Sam

Page 41 of 151

Basic Operations supported by a list in Javascript

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

JavaScript arrays (lists) support several fundamental operations that allow you to manipulate and access data efficiently. Here are the core operations you can perform on arrays. Basic List Operations Insertion − Add elements at the beginning, middle, or end of the list Deletion − Remove elements from any position in the list Display − Show the complete list contents Search − Find elements using specific values or conditions Access − Retrieve elements by their index position Insertion Operations You ...

Read More

Add elements to a linked list using Javascript

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

In JavaScript, adding elements to a linked list requires careful pointer manipulation to maintain the list structure. We need to create a function insert(data, position) that inserts data at the specified position. Implementation Steps Create a new Node with the provided data Check if the list is empty. If so, add the node as head and return Iterate to the desired position using a current element pointer Update the new node's next pointer to point to the current node's next Update the current node's next pointer to point to the new node Visual Representation ...

Read More

The Linked List Class in Javascript

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

Here is the complete implementation of the LinkedList class in JavaScript. This data structure allows you to store elements in a linear sequence where each element points to the next one. Complete LinkedList Implementation class LinkedList { constructor() { this.head = null; this.length = 0; } insert(data, position = this.length) { let node = new this.Node(data); if (this.head === null) ...

Read More

Removing Elements from a Double Linked List using Javascript

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

Removing an element from a doubly linked list involves updating the pointers of adjacent nodes to bypass the node being removed. There are three main cases to consider based on the position of the element. Three Cases for Removal Removing from head: Update head to point to the second node and remove the previous link from the new head node. Removing from tail: Update tail to point to the second-to-last node and set its next pointer to null. Removing from middle: Connect the previous and next nodes directly, bypassing the current node by updating their pointers. ...

Read More

Circular linked lists in Javascript

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

A Circular Linked List is a variation of the standard linked list where the first element points to the last element and the last element points back to the first element, forming a circle. Both singly and doubly linked lists can be implemented as circular structures. Data: 10 Data: 20 Data: 30 ...

Read More

How exactly does work?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 326 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

When should you use sets in Javascript?

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

Sets in JavaScript are ideal when you need to store unique elements where order doesn't matter and you primarily need to check for membership of different objects. Sets are also useful when you want to perform operations like union, intersection, and difference similar to mathematical sets. Let's explore both the built-in ES6 Set and understand when to use it effectively. When to Use Sets Use Sets when you need: Unique values only − Automatically prevents duplicates Fast membership testing − O(1) lookup time with has() Set operations − Union, intersection, difference between collections Simple deduplication ...

Read More

Clearing the set using Javascript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 197 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

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

How to set the space between characters in a text with JavaScript?

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

To set the space between characters in text, use the JavaScript letterSpacing property. This property controls the horizontal spacing between individual characters in a text element. Syntax element.style.letterSpacing = "value"; The value can be specified in pixels (px), em units, or other CSS length units. Negative values decrease spacing, while positive values increase it. Example: Setting Letter Spacing Here's a complete example that demonstrates how to set character spacing with JavaScript: Letter Spacing Example ...

Read More
Showing 401–410 of 1,507 articles
« Prev 1 39 40 41 42 43 151 Next »
Advertisements