To get a sub Set in TypeScript, you can use the 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: string[] = ['apple', 'banana', 'orange', 'grape', 'melon'];
// Get sub Set with items
const subSet: string[] = 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: string[] = [];
// Get sub Set from empty array
const subSet: string[] = 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 TypeScript language with well detailed examples.