javascript - value of an object from a variable -


this question has answer here:

i getting object looks this

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

i need value of discount.group_name if group_name = 'salesman' should 0, if group_name = manager should 0.05 , on.

i tried doing

console.log(discount.group_name) 

but didn't work.

please me.

you need use

console.log( discount[group_name] ); 

look bracket notation.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -