Slice is a js method which is used by an array (String is an array of char) and returns a shallow copy of the array selected from a start position to an end position.
According to the documentation
The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
For Example, "Hello, world".slice(0,5)
is equal to "Hello"
.
If you want to get a date 10 days earlier, you can init the current date and then take of 10 days. This can be done whith the setDate
and getDate
methods
const date = new Date()
date.setDate(date.getDate() - 10)
console.log(date.toISOString().slice(0,10))