0

I didn't really know how to parse the title very well but, what I need help with is I was watching a tutorial on how to make a programming language in python. I wanted to make it in javascript. I got the lexer working but then came to the parser. In the tutorial they do this:

t = {token['value']: []}

I want to do that in javascript. But when I try to do that I can user the token['value'] part to as a 'label' so to say.

Thanks!

  • [Duplicate](https://google.com/search?q=site%3Astackoverflow.com+js+use+expression+as+object+key) of [dynamic keys for object literals in Javascript](https://stackoverflow.com/q/6500573/4642212). – Sebastian Simon Nov 08 '20 at 01:46

1 Answers1

1

You may be looking for computed properties:

const t = {
  [token.value]: []
};

Then you will be able to access t[token.value].

elclanrs
  • 92,861
  • 21
  • 134
  • 171