• Register
0 votes
306 views

Problem :

Facing following chrome error
error in event handler for (unknown): typeerror: cannot read property 'indexof' of undefined
6 5 3
6,930 points

Please log in or register to answer this question.

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 + "^")
})
9 7 4
38,600 points

Related questions

0 votes
1 answer 1 view
1 view
Problem: var id = $('.getval_'+product_id+''+index+'').attr("id"); var value = ""; console.log(id); //data that return by id 6059 s2id_6061 6122 s2id_8410 if (id.indexOf('s2id_') > 0) { value = $('.getval_'+product_id+''+index+'').select2(' ... of ID don't have s2id_ it will go else statement. But the code return an error which is (Uncaught TypeError: Cannot read property 'indexOf' of undefined)
asked 22 hours ago ochena 22.1k points
0 votes
1 answer 8 views
8 views
Problem: Uncaught TypeError: a.indexOf is not a function” error when opening new foundation project
asked Mar 16 ummesalma 29.2k points
0 votes
1 answer 3 views
3 views
Problem: I am learning javascript from Mozilla developer network(MDN). I am getting error in Number guessing game. The error says "Uncaught TypeError: Cannot read property 'addEventListener' of null" at line 46.
asked 4 days ago padma1 34.3k points
1 vote
1 answer 4 views
4 views
Problem: I need the solution of this error: Uncaught typeerror: cannot read property 'top' of undefined.
asked Apr 27 PkGuy 23.5k points
1 vote
1 answer 7 views
7 views
Problem: Is there any way top avoid this error while using AJAX call ? Uncaught typeerror cannot read property length of undefined.
asked Apr 26 PkGuy 23.5k points
1 vote
1 answer 17 views
17 views
Problem : I'm trying to add jquery validation to containing ,I have a preexisting form.I use jquery validator plugin. I'm getting the error : Uncaught TypeError: Cannot read property 'call' of undefined I have no idea How to fix this.
asked Mar 21 Sabbir Hossain 14.6k points
1 vote
1 answer 30 views
30 views
Problem : I am building a basic app, When I check out the console after pressing my Dismiss "button", I get this: TypeError: Cannot read property 'id' of undefined at notificationFactory.js:94 at Function.m.extend.each (jquery.min.js:2) at Array.fooMessages. ... function)angular.js:2853 (anonymous function)angular.js:325 rangular.js:2852 cAny ideas on what I need to do to fix this? Thanks!
asked Mar 21 Sabbir Hossain 14.6k points
1 vote
1 answer 26 views
26 views
Problem : First time I pushing an array's contents to another array by seeing tutorial and I get this: "Uncaught TypeError: Cannot read property 'push' of undefined" Here is my code : var order = new Object(), stack = []; for(var i=0;i<a.length;i++){ if(parseInt(a[i].daysleft) == 0 ... ); } if(parseInt(a[i].daysleft) < 0){ order[2].push(a[i]); } }Any ideas on what I need to do to fix this? Thanks!
asked Mar 21 Sabbir Hossain 14.6k points
1 vote
1 answer 32 views
32 views
Problem : I am trying to execute the function manually.When i try to load a select list on document ready i get this error : Uncaught TypeError: Cannot read property 'toLowerCase' of undefined -> jquery-2.1.1.js:7300 Here is the code : $(document).ready(function() { $(" ... teacher.name); $('#TeacherSelect').append(option); }); }, error: function() { alert("Error while getting results"); } }); }
asked Mar 20 Sabbir Hossain 14.6k points
1 vote
1 answer 31 views
31 views
Problem : Why I got the error : *Uncaught TypeError: Cannot read property 'name' of undefined * I am new in javascript. Can you tell me what the problem is here?
asked Mar 20 Sabbir Hossain 14.6k points