javascript - jQuery iterate through loop delete elements -


i have javascript array of objects: each object contains key/value pairs. i'm trying iterate through array, , delete object value particular key (say "industry") fails match given value. here code, reason it's not looping through whole array, , think has fact when delete item loop counter botched somehow:

var industry = 'testing'; var = 0; (i = 0; < assets_results.length; i++) {      var asset = assets_results[i];     var asset_industry = asset['industry'];     if (industry != asset_industry) { assets_results.splice(i,1); }  }    

any ideas? in advance.

this because when splice 1 element, size of array decreases one. elements after splice shift 1 position beginning of array , fills space of spliced one. code misses 1 element.try code.

var industry = 'testing'; var = 0; (i = 0; < assets_results.length; i++) {      var asset = assets_results[i];     var asset_industry = asset['industry'];     if (industry != asset_industry) {                assets_results.splice(i,1);                i--;     }  }  

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -