'How do I check if a file name includes a variable in javascript?

So I am trying to make a save file system thing, and it creates a file with your username, but when you log in it checks the user saves file to see if theres a file called "[username]_save.txt", but I'm not sure how to do it with a username variable. Could someone help me out? thanks!

Solution 1:[1]

use Regular expresseion

let regexp = new RegExp(username)

if (regexp.test(filename))
  // true

Solution 2:[2]

Without additional code and examples of what you have so far it's a shot in the dark to help you, but here's a thought:

Use concatenation or template literal to incorporate the username into the filename you are looking for.


If you have more info on the issue we can provide more help!


This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zergski
Solution 2 Melongro