Front End Technology Articles - Page 600 of 860

Remove elements from a Set using Javascript

karthikeya Boyini
Updated on 15-Jun-2020 09:42:29

217 Views

The delete method checks if a value already exists in the set, if it does, then it removes that value from the set. We can implement it as follows &minusl Exampledelete(val) {    if (this.has(val)) {       delete this.container[val];       return true;    }    return false; }You can test this using − Exampleconst testSet = new MySet(); testSet.add(1); testSet.add(2); testSet.add(5); testSet.delete(5); testSet.delete(2); testSet.display(); console.log(testSet.has(5)); console.log(testSet.has(20)); console.log(testSet.has(1));OutputThis will give the output −{ '1': 1} False False TrueIn ES6, you use the delete function as follows − Exampleconst testSet = new MySet(); testSet.add(1); testSet.add(2); testSet.add(5); testSet.delete(5); ... Read More

Add elements to a Set using Javascript

Vivek Verma
Updated on 24-Jul-2025 15:31:09

257 Views

In JavaScript, a Set is an object that is used to store a collection of unique elements of different types, such as numbers, strings, booleans, and object references, etc. const mySet = new Set(); Adding Elements to a JavaScript Set We can add elements to a JavaScript set in the following ways: Using Simple add() Method Using Method Chaining with add() Using add() Method The add() method of the Set object accepts a value as a parameter and adds it to the elements of the current Set object, and returns ... Read More

Creating a Set using Javascript

karthikeya Boyini
Updated on 15-Jun-2020 09:48:57

607 Views

Let's create a MySet class so that it doesn't hide the actual set class in JS. We'll create a container object that'll keep track of all our values that we add to the set. We'll also create a display function that prints the set for us. Exampleclass MySet {    constructor() {       this.container = {};    }    display() {       console.log(this.container);    } }In ES6, you can directly create a set using the Set class. For example,  Exampleconst set1 = new Set(); const set2 = new Set([1, 2, 5, 6]);Checking for membershipThe has method checks ... Read More

When should you use sets in Javascript?

Samual Sam
Updated on 15-Jun-2020 09:50:56

196 Views

Whenever you want to store unique elements in a container for which the order doesn't matter and you mainly want to use it to check for membership of different objects.Sets are also useful when you want to perform operations like union, intersection, a difference like you do in mathematical sets.Let's look at both how we can define our own set and use the existing one in ES6.Methods we'll implementThe ES6 set API provides some methods. We'll implement these methods in our implementation and also look at how to use them using the built-in class.add() −  Adds a new element to the ... Read More

Set Data Structure in Javascript

karthikeya Boyini
Updated on 15-Jun-2020 09:52:17

538 Views

A set is an abstract data type that can store certain values, without any particular order and no repeated values. It is a computer implementation of the mathematical concept of a finite set. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests a value for membership in a set.

Doubly Linked List as Circular in Javascript

Samual Sam
Updated on 15-Jun-2020 09:17:59

251 Views

In the doubly linked list, the next pointer of the last node points to the first node and the previous pointer of the first node points to the last node making the circular in both directions.Insertions and deletions in a circular linked list are the same as other linked lists. You just need to keep track of the last link while performing operations on either end of the linked list.You can look up and try implementing Circular linked list using Circular Linked List Algorithm as a guide.

Singly Linked List as Circular in Javascript

karthikeya Boyini
Updated on 15-Jun-2020 09:18:26

290 Views

In the singly linked list, the next pointer of the last node points to the first node.

Circular linked lists in Javascript

Samual Sam
Updated on 15-Jun-2020 09:19:04

545 Views

Circular Linked List is a variation of the Linked list in which the first element points to the last element and the last element points to the first element. Both Singly Linked List and Doubly Linked List can be made into a circular linked list.

The Doubly Linked List class in Javascript

karthikeya Boyini
Updated on 15-Jun-2020 09:19:51

497 Views

Here is the complete implementation of the DoublyLinkedList Class −Exampleclass DoublyLinkedList {    constructor() {       this.head = null;       this.tail = null;       this.length = 0;    }    insert(data, position = this.length) {       let node = new this.Node(data);       // List is currently empty       if (this.head === null) {          this.head = node;          this.tail = node;          this.length++;          return this.head;       }       // Insertion at ... Read More

Removing Elements from a Double Linked List using Javascript

Samual Sam
Updated on 15-Jun-2020 09:22:15

592 Views

Removing an element is very easy in a linked list. We just need to get rid of the node we want to remove, ie, lose its reference. There are 3 cases we need to consider −Removing an element from head: In this case, we can simply assign head = head.next and remove the previous link from the next element. This way we'll lose the reference of the first element. And out head will start pointing to the second element.Removing an element from the tail: In this case, we can simply assign the node.next of second last node to be null ... Read More

Advertisements