I have a simple code like this:
var name = 'line1';
var obj = {};
obj.name = [0, 1];
console.log(obj);
Key of property is name. But I want to make key='line'. Can you help me?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If I understand correctly, and you want to use the value of the
namevariable as the property name, you can use this syntax:Object properties can also be accessed with the same syntax arrays use. It is handy in situations like this one.