How can the current number of i be accessed in a for of loop?

You can use the entries function. It will return a index/value pair for each entry in the array like: [0, “one”] [1, “two”] [2, “three”] Use this in tandem with array destructuring to resolve each entry to the appropriate variable name: const arr = [“one”, “two”, “three”] for(const [index, value] of arr.entries()) { console.log(index, value); … Read more

How to filter an object with its values in ES6

You can use reduce() to create new object and includes() to check if value of object exists in array. const acceptedValues = [“value1”, “value3”] const myObject = { prop1: “value1”, prop2: “value2”, prop3: “value3” } var filteredObject = Object.keys(myObject).reduce(function(r, e) { if (acceptedValues.includes(myObject[e])) r[e] = myObject[e] return r; }, {}) console.log(filteredObject)

using await on global scope without async keyword

Update When using Node, the file currently must have an .mjs extension to work. Top level awaits can be used in browser modules. When used the script tag must include the type attribute which must be set to module: <script src=”/script.js” type=”module”></script> const start = Date.now() console.log(‘Pre call.’) await delayedCall() console.log(‘Duration:’, Date.now() – start) function … Read more