Home Ask Login Register

Developers Planet

Your answer is one click away!

user2909855 February 2016

value of an object from a variable

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


but it didn't work.

Please help me.


Arup Rakshit February 2016

You need to use

console.log( discount[group_name] );

Look Bracket notation.

Post Status

Asked in February 2016
Viewed 1,196 times
Voted 9
Answered 1 times


Leave an answer

Quote of the day: live life