I need to change all instances of a string within an array, I could do it like this, But is there not a more elegant solution when they are key value pairs?
var person = [];
person.push({
name: 'John Smith',
description: 'John Smith is tall.',
details: 'John Smith has worked for us for 10 years.'
});
person.push({
name: 'Michael Smith',
description: 'Michael Smith is tall.',
details: 'Michael Smith has worked for us for 10 years.'
});
person.push({
name: 'Linda Smith',
description: 'Linda Smith is tall.',
details: 'Linda Smith has worked for us for 10 years.'
});
function replaceWordST() {
var toReplace = "Smith";
var replaceWith = "Jones";
for (i = 0; i < person.length; i++) {
person[i].name = person[i].name.replace(new RegExp(toReplace, 'g'), replaceWith);
person[i].description = person[i].description.replace(new RegExp(toReplace, 'g'), replaceWith);
// etcetc
}
}