How to put a variable in 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 in the "body:" variable? Or is it impossible to implement?
June 10th 19 at 16:13
1 answer
June 10th 19 at 16:15
Solution
Use template strings:
body: `Hey, ${userName}! You've been notified!`,
or concatenation:
body: "Hey," + userName + "! You've been notified!",
,
And how can you bring matches in arrays in the same console?
Some mistakes
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!",
 });
- ezequiel commented on June 10th 19 at 16:18
from your code it is not clear that error. - Lenny.Botsfo commented on June 10th 19 at 16:21
,
Figured out the correct option:
body: Object.keys(obj) - ezequiel commented on June 10th 19 at 16:24
why you needed to display the object in the body of the notice? - Lenny.Botsfo commented on June 10th 19 at 16:27
the extension parses certain properties received for sale skins (items). And that would be it was easier for me to find this skin that came with I need content, I need to know the name of this object - ezequiel commented on June 10th 19 at 16:30
it's nice to prepare the data and humanly to display. - Lenny.Botsfo commented on June 10th 19 at 16:33
for personal use it will come ))) - ezequiel commented on June 10th 19 at 16:36

Find more questions by tags JavaScriptNotifications