JavaScript MCQ Basic JavaScript MCQ Question #4838
Single Choice Not Set

QWhich of the following String object functions returns the character in the string beginning at the provided position through the specified number of characters?

ID: #4838 Basic JavaScript MCQ 325 views
Question Info
#4838Q ID
Not SetDifficulty
Basic JavaScript MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A slice()
  • B split()
  • C substr()
  • D search()
Correct Answer

Explanation

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 Question

Challenge a friend or share with your study group.