JavaScript Closing a notification


Example

You can close a notification by using the .close() method.

let notification = new Notification(title, options);
// do some work, then close the notification
notification.close()

You can utilize the setTimeout function to auto-close the notification sometime in the future.

let notification = new Notification(title, options);
setTimeout(() => {
    notification.close()
}, 4000);

The above code will spawn a notification and close it after 4 seconds.