javascript - id is undefined when removing an element from an array -


i have array of object

var country = [];

it

{     "name" : "ind"     "capital" : "delhi"     id : someid1 }, {     "name" : "usa"     "capital" : "ws"     id : someid2 }, {     "name" : "uk"     "capital" : "london"     id : someid3 } 

now want delete on of element on condition. throwing error more 2 record.

my error : cannot read property 'id' of undefined

my code

remove : function(me, record, index){     var countryrec = this.country;     var countrylen = this.country.length;     for(var i=0; i<countrylen; i++){         if(record.data.id == this.countryrec[i].id){             //delete this.checkrec[i];             checkrec.splice(i,1);         }     } } 

this throwing error more 2 record. please suggest me doing wrong.

assuming, have unique id, leave loop after splicing break

var countryrec = this.country; var countrylen = this.country.length; (var = 0; < countrylen; i++) {     if(record.data.id == countryrec[i].id) {         countryrec.splice(i, 1);         break;     } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -