Raymond Pang
Raymond Pang

Reputation: 807

How to substitute string into expression which accesses Json object

I want to express fileName = req.files.raymond.originalFilename; But I don't know if it is "raymond" beforehand. So, I have to substitute a variable into the expression (req.body.key has the name I need )

const name = req.body.key;
const fileName = req.files.name.originalFilename;

But this way of substitution doesn't work. What is the correct way to do this?

Upvotes: 2

Views: 49

Answers (1)

thewolff
thewolff

Reputation: 571

Try:

req.files[name].originalFilename

Upvotes: 2

Related Questions