DEV Community

Discussion on: A neat little trick with JavaScript's indexOf()

Collapse
 
alainvanhout profile image
Alain Van Hout

It's indeed interesting, no doubt about that :).

It reminds me a bit of the following line of JavaScript, that was making the round a couple of years ago, and which manages to showcase a lot of neat JS with very little code: (source)

[].forEach.call($$("*"),function(a){
  a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)
})

Back to the original topic, I wrote my response from the perspective of 'should this be used?', which isn't so much a matter of interestingness as it is one of maintainability. That's not the same as saying it's 'bad', but in any setting where you're not the only contributing developer, code generally has to do better than simply not being bad.

(of course I'm ignoring the already mentioned String.prototype.includes() in all this)