mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-12 10:00:39 -04:00
fix(curriculum):add code example for str.match() in step 35 of calorie counter project (#53461)
This commit is contained in:
@@ -6,8 +6,13 @@ dashedName: step-35
|
||||
---
|
||||
|
||||
# --description--
|
||||
Strings have a <dfn>.match()</dfn> method, which takes a regex argument. `.match()` will return an array of match results – containing either the first match, or all matches if the global flag is used.
|
||||
|
||||
Strings have a `.match()` method, which takes a regex argument. `.match()` will return an array of match results – containing either the first match, or all matches if the global flag is used.
|
||||
```js
|
||||
const str = 'example string';
|
||||
const regex = /example/;
|
||||
const result = str.match(regex); // Returns ['example']
|
||||
```
|
||||
|
||||
Return the result of calling the `.match()` method on `str` and passing your `regex` variable as the argument. You'll use this match result later on.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user