object - How do i point two fields to use the same value in javascript -


i have object below, , can see, "valid" , "pending" using same value, there way put in 1 line rather duplicating "custom-info" ?

  map = {     'failed': 'custom-error',     'pending': 'custom-info',     'valid': 'custom-info'   }; 

you can assign string value constant , set property value using constant.

const customer_info = 'custom-info'; map = {     'failed': 'custom-error',     'pending': customer_info,     'valid': customer_info   }; 

this helps if setting property value many times , used somewhere else otherwise setting string value in object fine.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -