I need to remove 'hello' substring from each object field in objects array. And i have an error "Cannot read property 'indexOf' of null". It happens, because i try to change object field in loop. But What to do? :) I use AngularJS.
var array = [
{text: 'hello user1'},
{text: 'hello user2'},
{text: 'user3'},
{text: 'hello user4'},
];
for (i = 0; i < array.length; i++) {
if (array[i].text.indexOf('hello') + 1) {
array[i].text = array[i].text.replace('hello','');
}
}
// For demo
document.write(JSON.stringify(array));