Programmers learn & share
0 votes
61 views

Problem :

Facing following chrome error
error in event handler for (unknown): typeerror: cannot read property 'indexof' of undefined
by (6.9k points)   | 61 views

1 Answer

0 votes

Solution :

1. No need to use a jQuery each for this. 

2. No need to alter an array that you are operating on. If you want to remove elements from an array then you can use filter. Filter has following signature:

someArray.filter(function(item, index, array) {
  // filter to return a value that is truthy to keep an item or falsey to remove it
})

3. Filter always returns a new array with only the values that match what you want.In your case it should look as follows:

e.g
var filteredProducts = cart_products.filter(function(item) {
  return item.indexOf(product + "^")
})
by (36.1k points)  
2,204 questions
2,608 answers
59 comments
241 users