var fields = {
100: 'Harry',
200: 'Zack'
};
var required = 200;
How can I get the output of Zack? I know there is a utility in lodash but not quite sure how to use it.
var fields = {
100: 'Harry',
200: 'Zack'
};
var required = 200;
How can I get the output of Zack? I know there is a utility in lodash but not quite sure how to use it.
You can make use of plain Javascript.
var result = fields["200"]
or
var result = fields[required]
The important thing to note is that Javascript properties are internally stored as string.
You could use get:
var result = _.get(fields, required);