The NodeList don't have a indexOf(element) method? So, how can I get the element index?
The indexOf() method returns the first index (position) of a specified value. The indexOf() method returns -1 if the value is not found. The indexOf() method starts at a specified index and searches from left to right. By default the search starts at the first element and ends at the last.
indexOf() The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.
To find the index of an object in an array, by a specific property: Use the map() method to iterate over the array, returning only the value of the relevant property. Call the indexOf() method on the returned from map array. The indexOf method returns the index of the first occurrence of a value in an array.
indexOf() The indexOf() method, given one argument: a substring to search for, searches the entire calling string, and returns the index of the first occurrence of the specified substring.
You can use Array.prototype.indexOf.call()
like this
let nodes = document.getElementsByTagName('*'); Array.prototype.indexOf.call(nodes, document.body);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With