To get a sub Set in JavaScript, you can use Array.slice() method.
In this example,
mySet
containing elements of a specific type.slice()
method with the specified range to get the sub Set.// Define array with items
const mySet = ['apple', 'banana', 'orange', 'grape', 'melon'];
// Get sub Set with items
const subSet = mySet.slice(1, 4);
console.log('Sub Set with items:', subSet);
Sub Set with items: [ 'banana', 'orange', 'grape' ]
In this example,
mySet
.// Define empty array
const mySet = [];
// Get sub Set from empty array
const subSet = mySet.slice(1, 4);
console.log('Sub Set from empty array:', subSet);
Sub Set from empty array: []
In this tutorial, we learned How to get Subset from a Set in JavaScript language with well detailed examples.