tl;dr: String.prototype.search() is basically .indexOf() but with regexes. It's been supported in every browser since IE 4, but ES6 made it more p...
For further actions, you may consider blocking this person and/or reporting abuse
Hidden gem 💎 for sure, thanks! 🚀
if ye want another exciting fact about browser js:
element.append is a thing and accepts multiple dom elements.
(me being one of the people who started with js when netscape had that nice brushed aluminium theme literally missed the addition of this neat little function)
Wow, I learnt way more than just the search method. What an article!
TIL me too!
Right??
Symbol.search huh - I do like that syntax.
Thanks for sharing Ken. It's very useful. Learnt something new today :-)
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 guessGreat to know ! Thanks for sharing :)
wow, thank you!
I dont know about "data-*" in html, when do use it?
Hey! That's a bit off-topic for this article, so I don't want to go over it in this comments section, but I love talking about that sort of thing, so DM me if you want to talk about it!
OMG! Data lake in JS. Yeah!