How to extract a part of string using JavaScript

the slice() function extracts and returns a portion of a given string: