Hello I have an issue with findIndex specifically with IE11. It doesn't work!
Can someone help me change this to work with IE11.
var index = items.findIndex(x => x.id==id)
if (index != -1)
{
items[index].q = items[index].q+1;
localStorage.setItem('products', JSON.stringify(catItems));
}
I have tried this but can't figure out exactly what I need to change in order for the current item's q to increment by 1:
if (items.filter(function(e) { return e.id === id; }).length > 0) {
//how to get the current item q and increment
}
Any help appreciated, cheers!
You try by changing arrow function to normal function
var arrayIs = [23,45,67,1,30,45,60] var searchValue; function getIndex(d,i) { if(d==searchValue) return i; } searchValue = 10; console.log(arrayIs.findIndex(getIndex)); // -1(not found) searchValue= 30; console.log(arrayIs.findIndex(getIndex)); // 4(found at index 4)If above solution is not work then you can try, traditional approach
let arrayIs = [23,45,67,1,30,45,60] function getIndex(array, searchValue) { for(var i=0; i<array.length; i++){ if(array[i]==searchValue) return i; } return -1; } console.log(getIndex(arrayIs, 10)); // -1(not found) console.log(getIndex(arrayIs, 30)); // 4(found at index 4)If, IE support let then don't use var, instead of var use let