This is a homework assignment.
I'm trying to use the value from one object as a key for another.
for example...
const myObj = { key: "myKey" } const myObj2 = { <--- here i need the value from myObj's key field. So, I thought to put something like myObj.key.value but that didnt work so I'm at a loss. I'm fairly new to javascript so this is a little over my head. }
Try this:
const myObj = { key: "myKey" }; const myObj2 = { [myObj.key]: "123" }; console.log(myObj2);
1.4m articles
1.4m replys
5 comments
57.0k users