Meta_Data - 1 year ago 66

Javascript Question

This is a python code to create a dictionary and update it with standard mathematical functions. How can I do the same in javascript?

`import math`

Env = dict # An environment is a mapping of {variable: value}

env = Env()

env.update(vars(math)) # sin, cos, sqrt, pi, ..

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You can read properties of `Math`

with `getOwnPropertyNames`

object and then reduce it:

```
const dict = {};
Object.getOwnPropertyNames(Math).reduce((r, k) => {
r[k] = Math[k];
return r;
}, dict);
```