P
P
peterBOG2017-12-11 12:00:47
JavaScript
peterBOG, 2017-12-11 12:00:47

How to add a variable to the notification body?

var stickerTitle = sticker.getAttribute('title');
      var arr = stickerTitle.split('\n').filter(str=>{return str.length > 0})
      let arr2 = ['Wear: 0% - Unscratched', '50% of the proceeds from the sale of this sticker support the included players and organizations.'];
    let obj = {};
    
    for (let i = 0; i < arr.length; i += 1) {
      if (arr2.includes(arr[i])) {
        obj[arr[i]] = true;
      }
    }
         if (Object.keys(obj).length){
         var notification = new Notification('Notification title', {
      icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
      body: "Hey there! You've been notified!",
    });

How to specify a variable in "body:"? Or is it impossible to implement?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2017-12-11
@peterBOG

Use template strings : or concatenation :

body: "Hey, " + userName + "! You've been notified!",

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question