Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - Use variable inside push string

Tags:

javascript

I am trying to have the data-max value display dynamically inside of the err.push() string to show how many files that e allows.

How do I get the data-max variable to dynamically appear in the error message string?

  let maxFileNum = e.target.getAttribute('data-max'); //Maximum number of files
  if (fileList.files.length > maxFileNum) {
    let tmpf = [];
    err.push('Limit of ${maxFileNum} images allowed');
    fileList.files = tmpf;
  }
like image 292
Kyle Underhill Avatar asked Aug 31 '26 00:08

Kyle Underhill


1 Answers

You will have to use back ticks (``) to represent a string literal:

  let maxFileNum = e.target.getAttribute('data-max'); //Maximum number of files
  if (fileList.files.length > maxFileNum) {
    let tmpf = [];
    err.push(`Limit of ${maxFileNum} images allowed`);
    fileList.files = tmpf;
  }
like image 140
PotatoParser Avatar answered Sep 02 '26 12:09

PotatoParser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!