0

I am getting an object that looks like this

discount = {salesman: 0, supervisor: 0.02, manager: 0.05};
group_name = 'salesman';

I need to get the value of discount.group_name so if the group_name = 'salesman' I should get 0, if the group_name = manager I should get 0.05 and so on.

I tried to get it by doing

console.log(discount.group_name)

but it didn't work.

Please help me.

Tushar
  • 85,780
  • 21
  • 159
  • 179

1 Answers1

3

You need to use

console.log( discount[group_name] );

Look Bracket notation.

Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317