n JavaScript, the slice() method is used to extract a section of an array or a string and returns a new array or string containing the selected elements. It does not modify the original array or string; instead, it creates a shallow copy of the selected portion.
The syntax for the slice() method is as follows:
array.slice(startIndex, endIndex)