The isDisjointFrom() method of the Set object in JavaScript takes another set as an argument and returns a boolean indicating if the original set has no elements in common with the given set.
The syntax of Set.isDisjointFrom() method is:
isDisjointFrom(other)
This isDisjointFrom() method of Set takes a set and returns a boolean indicating if this set has no elements in common with the given set.
Parameter | Optional/Required | Description |
---|---|---|
other | required | The set to compare with the original set. |
Set.isDisjointFrom() returns value of type boolean
.
In JavaScript, we can use the isDisjointFrom()
method to check if two sets of numbers have no elements in common.
For example,
setA
with initial values 1, 2, and 3.setB
with initial values 4 and 5.isDisjointFrom()
method to check if setA
and setB
are disjoint.console.log()
.const setA = new Set([1, 2, 3]);
const setB = new Set([4, 5]);
const isDisjoint = setA.isDisjointFrom(setB);
console.log(isDisjoint);
true
In JavaScript, we can use the isDisjointFrom()
method to check if two sets that have common elements are not disjoint.
For example,
setA
with initial values 'apple', 'banana', and 'cherry'.setB
with initial values 'banana' and 'cherry'.isDisjointFrom()
method to check if setA
and setB
are disjoint.console.log()
.const setA = new Set(['apple', 'banana', 'cherry']);
const setB = new Set(['banana', 'cherry']);
const isDisjoint = setA.isDisjointFrom(setB);
console.log(isDisjoint);
false
In JavaScript, we can use the isDisjointFrom()
method to check if two sets of objects have no elements in common.
For example,
setA
with initial objects representing different people.setB
with different objects representing different people.isDisjointFrom()
method to check if setA
and setB
are disjoint.console.log()
.const person1 = { name: 'John' };
const person2 = { name: 'Jane' };
const person3 = { name: 'Doe' };
const setA = new Set([person1]);
const setB = new Set([person2, person3]);
const isDisjoint = setA.isDisjointFrom(setB);
console.log(isDisjoint);
true
In this JavaScript tutorial, we learned about isDisjointFrom() method of Set: the syntax and few working examples with output and detailed explanation for each example.