You can't use commas for this. You have to have separate [ ]
operators.
tempFiles[req.query.tenant][file.name]=finalName;
Perversely, your code was not a syntax error because the comma operator does exist. The meaning of your version was:
- evaluate the expression
req.query.tenant
- throw that value away
- evaluate the expression
file.name
- use that value as a property name to look up in the object referenced by "tempFiles"
Also, note that if you really just declared your array right before trying to make that assignment, it won't work. You have to explicitly create the second dimension:
var tempFiles = [];
tempFiles[ req.query.tenant ] = [];
tempFiles[ req.query.tenant ] [ file.name ] = finalName;
Finally, if the property names involved — req.query.tenant
and file.name
— are strings, then you really shouldn't be using arrays anyway. You should be creating plain objects:
var tempFiles = {};
tempFiles[ req.query.tenant ] = {};
tempFiles[ req.query.tenant ] [ file.name ] = finalName;