Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. 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}, ]
  2.  
  3. const message = `Hello {{name}}, welcome to {{country}}`
  4.  
  5. function validate(message){
  6. return true
  7. }
  8.  
  9.  
  10. const contactKeys = Object.keys(contacts[0])
  11.  
  12. const newMessages = contacts.map(contact => {
  13. let msg = message
  14. contactKeys.forEach(key => {
  15. msg = msg.replace(`{{${key}}}`, contact[key])
  16. })
  17.  
  18. return {msg, number: contact.no}
  19. })
  20.  
  21. console.log(newMessages)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement