79155325

Date: 2024-11-04 11:52:02
Score: 1
Natty:
Report link

The match method can be used in JavaScript.

function findCharIndex() {
    haystack = "this is a string" 
    needle = "a" // "is","string"
    let matchWord = haystack.match(needle);
    if(!matchWord){
        return -1;
    }
    return matchWord.index;
};

console.log(findCharIndex());
Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Dharmendra Singh Patel