- A slice()
- B split()
- C substr()
- D search()
- Share this MCQ
Answer:
C
Share this MCQ
The substr() method extracts a specified number of characters from a string,
starting at a specified index position.
Here's an example of how to use it:
let str = 'Hello World';
let sub = str.substr(6, 5); // Extract 5 characters starting at index 6
console.log(sub); // Output: "World"
The substr()
method is similar to the substring()
method, which also extracts characters from a string.
The main difference between the two is that substring()
does not allow negative indexes, whereas substr() does.
Share this MCQ