Listing 19.03 - Chaining calls to replace
JS Bin
var data = {
author : "Oskar",
social : "@appOskar51"
};
var before = "Follow {{author}} {{social}}";
var after = before
.replace("{{author}}", data.author)
.replace("{{social}}", data.social);
console.log(before);
console.log(after);
Listing 19.03 - Chaining calls to replace - Tasks 2 to 4
- Replace the author property in the data with two new properties: firstName and lastName.
- Update the placeholders in the before string to use the new properties.
- Update the calls to the replace method so all three placeholders are filled with data.
var data = {
firstName : "Oskar",
lastName : "Smith",
social : "@appOskar51"
};
var before = "Follow {{firstName}} {{lastName}} {{social}}";
var after = before
.replace("{{firstName}}", data.firstName)
.replace("{{lastName}}", data.lastName)
.replace("{{social}}", data.social);
console.log(before);
console.log(after);