I get true for the below
function myFunction1() {
  var text = "hello world";
  var regex = /hello/;
  var result = regex.test(text);
  console.log((result));
}
Why am I getting false for this?
function myFunction() {
  var array = ["2023", "2022", "2020"];
  var regex = new RegExp("^20\d{2}$");
  for (var i = 0; i < array.length; i++) {
    var result = regex.test(array[i]);
    console.log(typeof(array[i]),result);
  }
}
The output is false for all the items in the array
I also tried changing the regex pattern as 20\d{2} but still getting false
Should the result not be true?


 
     
    