lundi 22 avril 2019

Can someone explain to me how this search bar code works? [duplicate]

This question already has an answer here:

I managed to get this specific search bar code: https://www.w3schools.com/howto/howto_js_filter_table.asp

to work and I understand the majority of how it works - except how the actual filtering (matching the user input to the cell contents) works. specifically this line of code:

if (txtValue.toUpperCase().indexOf(filter) > -1)

Could someone please explain to me why the index of the user input needs to be greater than -1?

I understand pretty much the rest of the code, but quite confused on this part.

Full code here: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_filter_table

(and if anyone could also guide me (if it's possible) to make the filtering applicable for more than one column, that'd also be great :) )

Thanks!




Aucun commentaire:

Enregistrer un commentaire