Error: Couldn’t find preset “es2015” relative to directory “/Users/username”
You only need to install babel-preset-es2015: CLI usage example: npm install babel-cli babel-preset-es2015
You only need to install babel-preset-es2015: CLI usage example: npm install babel-cli babel-preset-es2015
Use the Map.prototype.entries function, like this const m = new Map(); m.set(‘key1’, {}) m.set(‘keyN’, {}) console.log(m.entries().next().value); // [ ‘key1’, {} ] If you want to get the first key, then use Map.prototype.keys, like this console.log(m.keys().next().value); // key1 Similarly if you want to get the first value, then you can use Map.prototype.values, like this console.log(m.values().next().value); // … Read more
You can get array of keys with Object.keys() and then use map() to get values. var obj = { foo: ‘bar’, baz: 42 }; var values = Object.keys(obj).map(function(e) { return obj[e] }) console.log(values) With ES6 you can write this in one line using arrow-functions. var values = Object.keys(obj).map(e => obj[e])
When you make something const in JavaScript, you can’t reassign the variable itself to reference something else. However, the variable can still reference a mutable object. const x = {a: 123}; // This is not allowed. This would reassign `x` itself to refer to a // different object. x = {b: 456}; // This, however, … Read more
You can use an empty object as fallback, and if D is null or undefined the assigned variables will be undefined. const D = null; const { a, b, c } = D || {}; console.log(a, b, c); Using typescript you need to add the correct type (or any) to the FALLBACK object (TS playground). … Read more
2018 Update: The module loader spec is now a part of the ES Spec – what you are describing is allowed and possible with <script type=”module”> in browsers and with a custom –loader with Node.js as well as with Deno if you’re into that. The module loader spec and the import/export syntax are separate. So … Read more
What is an applicable example of using Maps over objects? I think you’ve given one good example already: You at least need to use Maps when you are using objects (including Function objects) as keys. in particular, “when would keys be unknown until runtime?” Whenever they are not known at compile time. In short, you … Read more
In Resharper 2016 this has been renamed to ECMAScript 2015. It’s available under Resharper Options | Code Editing | Javascript | Inspections
You can use Array.from: Array.from(foo).join(‘ ‘) or the spread syntax: […foo].join(‘ ‘)
You have to specify default explicitly: export default function translateDate(date) { .. }