Can someone help me with the syntax for how to loop through an object literal using jQuery $.each
and replace strings that match in each item?
If I have:
var foo = {
item1: "Mary had a little lamb",
item2: "Whose fleece was white as snow",
item3: "Johnny ha a little lamb",
item4: "What's the deal with lambs?"
}
And I want to replace the word lamb
with lion
, where inside the $.each function do I replace the item?
I've tried:
$.each(foo, function(key, value){
return value.replace(/lamb/, "lion");
}
But it doesn't replace the items?