Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js object using variable as key

let yourKeyVariable = "Fire";
{
    [yourKeyVariable]: someValue,
}

/* object will resolve to { Fire : someValue } */

/*
 This is similar to adding k-v pair to an object using the other syntax 
ie. object[yourKeyVariable] = someValue; 
*/
 
PREVIOUS NEXT
Tagged: #js #object #variable #key
ADD COMMENT
Topic
Name
5+8 =