0 votes
in JavaScript by
What is the purpose of exec method in javascript?

1 Answer

0 votes
by

The purpose of exec method is similar to test method but it executes a search for a match in a specified string and returns a result array, or null instead of returning true/false.

var pattern = /you/;
console.log(pattern.exec("How are you?")); //["you", index: 8, input: "How are you?", groups: undefined]
...