Full-time web dev; JS lover since 2002; CSS fanatic. #CSSIsAwesome
I try to stay up with new web platform features. Web feature you don't understand? Tell me! I'll write an article!
He/him
Yeah, you definitely could do it that way, utilize myregex.exec() or myregex.match() inside of your method. Could be a nice way to encapsulate some ugly, repetitive logic, especially if you did this sort of thing all the time and wanted to write a factory function to take a regex and generate these search objects. Again, I don't really know if it's any cleaner in the end than just defining a findIndex(str, pattern) function, especially if not everyone reading your code will know about these symbols and understand how you're using them, but when I have the choice, I usually prefer dealing with native methods like str.search(pattern), since they have well-defined behavior and I know what to expect. Personal preference, I guess
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
So you can make extra wrapper for exec / match method to simplify code in the userland.
Yeah, you definitely could do it that way, utilize
myregex.exec()
ormyregex.match()
inside of your method. Could be a nice way to encapsulate some ugly, repetitive logic, especially if you did this sort of thing all the time and wanted to write a factory function to take a regex and generate these search objects. Again, I don't really know if it's any cleaner in the end than just defining afindIndex(str, pattern)
function, especially if not everyone reading your code will know about these symbols and understand how you're using them, but when I have the choice, I usually prefer dealing with native methods likestr.search(pattern)
, since they have well-defined behavior and I know what to expect. Personal preference, I guess