I’m debugging some code and have found the following code snippet and just don’t get what it does:
function appendModelPrefix(value, prefix) {
if (value.indexOf("*.") === 0) {
value = value.replace("*.", prefix);
}
return value;
}
What does my value string has to look like to get validated by the if-condition?
And to what does “*.” exactly do? I don’t get the wildcard…
I doesn’t wildcard. It searches for and then replaces a literal
"*."byprefixindexOffinds the first occurence of"*."in the string:So your consition will succeed if the string starts with a “*.” (index 0)
The replace method will then replace this first occurence of “*.” with the chosen prefix
BTW, you only get wildcard replacements if you use regexes instead of string patterns: