javascript - Strange undefined jquery error -


i trying itterate trough jquery array, , having error script causing error is:

$.each(amount, function (key, value) {     console.info('>>> selected line: '+value.value + " " + value.currency);     if ((value.currency == currency) && (value.value == val)) {         amount.splice(key,1);         console.info('deleted: [' + value.value + " " + value.currency+ "] line "+ key);     } }); 

the error firebug throws is:

typeerror: value undefined 

could point me error or how fix error?

the issue .splice(). when remove item 0, moves spot, no longer have item 1.

generally speaking, can't remove items list you're enumerating (unless taking steps adjust current index when adding or removing items, but.. yuck).

i recommend using filter function grep instead:

http://jsfiddle.net/dnn4a/

var newarr = $.grep(amount, function(item, idx) {    return item.currency == currency || item.value == val;  }, true); 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -