Test Method JS

PHOTO EMBED

Sat Dec 18 2021 16:52:43 GMT+0000 (Coordinated Universal Time)

Saved by @TheCodeWalker #javascript #test #method

let myString = "Hello, World!";
let myRegex = /Hello/;
let result = myRegex.test(myString); // result === true
content_copyCOPY

JavaScript has multiple ways to use regexes. One way to test a regex is using the .test() method. The .test() method takes the regex, applies it to a string (which is placed inside the parentheses), and returns true or false if your pattern finds something or not.