I am struggling to remove the 'hello5' from the years in myObj.
Although I tried using the 'pop' prototype, an error occurred in the browser console displaying:
'Uncaught TypeError: Cannot read property 'type' of undefined'
The following code snippet illustrates my issue. Feel free to try it and see the error message in the console.
I have spent a significant amount of time attempting to find a solution with no success so far. Your advice and solution would be greatly appreciated.
Code :
var myObj = {
test : 'testObje',
langs : {
0 : 'EN',
1 : 'GR',
2 : 'RU',
3 : 'TR'
},
comment : 'testComment'
};
var years = [];
for (i= 0; i<=10; i++)
{
years.push({
operator : i,
type : 'hello' + i
});
};
myObj.years = years;
var myObjLeng = myObj.years.length;
for(var i = 0; i < myObjLeng; i++) {
if(myObj.years[i].type == 'hello5') {
myObj.years.pop();
}
}