JS Coding Questions Logo
JS Coding Questions
#161💼 Interview💻 Code

What is the purpose of exec method

Advertisement

728x90

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.

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

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 76

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
161of476