Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Computed property names

//Use [] , that will be computed and used as the property name.

const key1 = "name";
const key2 = "age";
const student = {
    [key1]:"john Doe",
    [key2]:26
}
console.log(student)
//{ name:"john Doe", age:26 }
 
PREVIOUS NEXT
Tagged: #Computed #property #names
ADD COMMENT
Topic
Name
3+4 =