Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement