Created
July 24, 2017 00:27
-
-
Save robophil/e17955a3d9c7a01adbc94d59ff3b6601 to your computer and use it in GitHub Desktop.
Simple approach to mapping contact data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const contacts = [{id: 1, name: "DF lade", country: "nig", no: 090}, {id: 2, name: "Miss Akesuwa", country: "nig", no: 090}, {id: 3, name: "wendy", country: "nig", no: 090}, ] | |
const message = `Hello {{name}}, welcome to {{country}}` | |
function validate(message){ | |
return true | |
} | |
const contactKeys = Object.keys(contacts[0]) | |
const newMessages = contacts.map(contact => { | |
let msg = message | |
contactKeys.forEach(key => { | |
msg = msg.replace(`{{${key}}}`, contact[key]) | |
}) | |
return {msg, number: contact.no} | |
}) | |
console.log(newMessages) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment