JavaScript Set delete() Method Tutorial

In this section, we will learn what the Set delete() method is and how to use it in JavaScript.

What is JavaScript Set delete() Method?

If we want to delete a specific element in a `Set` object, we use the `delete()` method.

JavaScript Set delete() Method Syntax:

delete(value)

delete() Function Parameters:

The method takes one argument and that is the value in which we want to be deleted from the target `Set` object.

delete() Function Return Value:

The return value of calling this method is `true` if the target value removed successfully, otherwise `false`.

The value `false` returns usually because the value we want it to be removed does not exist in the first place!

Example: using Set delete() method in JavaScript

const collect = new Set();

collect.add("Jack");

collect.add("Jack");

collect.add("Omid");

collect.add("John");

console.log(collect.delete("Jack"));

console.log(collect.delete(1000));

Output:

true

false

Leave a Reply