I want to provide a value for object property but it is coming from another object. This is situation like this:
c.query('SELECT `' + field + '` FROM `table` WHERE `' + field + '` = :' + field,
{ field: value })
.on('result', function(res) {
res.on('row', function(row) {
callback(inspect(row));
});
});
i want to automate it in the way that i send object {field: 'someField', value: 'someValue'}
and i use reference to set property of object in second line of the code above.
I came up with this code:
var a = {
field: 'email',
value: 'john.doe@gmail.com'
};
var b = {
[a.field]: a.value
};
console.log(b);
it does work in here: jsFiddle, but in actual node.js server script it return error unexpected token "["
so its like i cannot set object property from another object property reference. Anyone has some idea?