Home > Blockchain >  How do I check if a file name includes a variable in javascript?
How do I check if a file name includes a variable in javascript?

Time:05-13

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!

CodePudding user response:

use Regular expresseion

let regexp = new RegExp(username)

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

CodePudding user response:

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.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

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

  • Related