I have the following if statement:
if (buyArray.indexOf(dealWith,0) != -1){
Which is breaking in ie (ie 8 on XP) with "object doesn't support this property or method".
Anyone have a work around for this?
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.
Yes, indexOf() works with array (of number, string, or any object), as well as with string.
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.
JavaScript String indexOf() It defaults to zero (0), meaning that if you omit the fromIndex , the search will start from the beginning of the string. The indexOf() always perform a case-sensitive search. To find the index of the last occurrence of a substring in a string, you use the lastIndexOf() method.
yeah, IE<9 doesn't support indexOf
. You can implement a shim like the one showed here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
Or if you already using jQuery you can use inArray. Also underscore has an implementation for it.
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