what is the working mechanism and principle of the split () method in JavaScript? I"m a little confused by the following code?
{
console.log("xdhg-sharp-sharp".split(/-sharp/y));
// [ "xdhg" "", ""]
console.log("-sharp-sharpx".split(/-sharp/y));
// [ "", "", "x" ]
console.log("-sharpx-sharp".split(/-sharp/y));
// [ "", "x" ,""]
console.log("-sharp-sharp".split(/-sharp/y));
// [ "", "", "" ]
}
my question point:
(1) since the y modifier is also called a sticky character (the y modifier symbol implies the header matching flag ^), why can the string "xdhg-sharp-sharp" be regularly matched by /-sharp/y?
(2 what is the mechanism inside the) split () method? Is it similar to an iterator trader?
I would like to ask all of you to give me some advice as a rookie. Thank you