Filter or map nodelists in ES6

What is the most efficient way to filter or map a nodelist in ES6? Based on my readings, I would use one of the following options: [...nodelist].filter or Array.from(nodelist).filter Which one...

Typescript es6 import module "File is not a module error"

I am using typescript 1.6 with es6 modules syntax. My files are: test.ts: module App { export class SomeClass { getName(): string { return 'name'; } } } main.ts: import App...

How overwrite .stack when inheriting from the native Error class?

(on node version '4.2.1', v8 '4.5.103.35') var TE = class tError extends Error { constructor(message) { super(message); this.name = tError.name; Error.captureStackTrace(this,...

ES6: import module from URL

Is it possible to import javascript module from external url in ES6? I tried (using babel-node): import mymodule from 'http://...mysite.../myscript.js'; // Error: Cannot find module...

`if __name__ == '__main__'` equivalent in javascript es6 modules

Is it possible to check if JavaScript file is being run directly or if it was required as part of an es6 module import. for example a main script is included. // main.js import './other'; if...

Does Jest support ES6 import/export?

If I use import/export from ES6 then all my Jest tests fail with error: Unexpected reserved word I convert my object under test to use old school IIFE syntax and suddenly my tests pass. Or, take...

What is SpreadElement in ECMAScript documentation? Is it the same as Spread syntax at MDN?

At ECMAScript specification the SpreadElement is described SpreadElement[Yield]: ...AssignmentExpression[In, ?Yield] Is this the same as the Spread syntax Spread syntax allows an iterable such...

Why can I not use `new` with an arrow function in JavaScript/ES6?

As far as I know, the arrow function is similar to a normal function. There aren’t any problem when I use it like this: let X = () => {}; let Y = function() {}; X(); Y(); However, the error...

Koa2 request.body is empty

I am working on a web service with koa2 and node6. My koa dependencies as follows; "koa": "^2.0.0-alpha.4", "koa-async-body": "^1.0.4", "koa-bodyparser": "^3.2.0", "koa-logger":...

How can I alias a default import in JavaScript?

Using ES6 modules, I know I can alias a named import: import { foo as bar } from 'my-module'; And I know I can import a default import: import defaultMember from 'my-module'; I'd like to alias...

ES6 - Finding data in nested arrays

In ES6 using find or filter I'm quite comfortable iterating through to find an element in an array using a value. However, I'm trying to get a value from a parent array based upon a value from a...

Is swapping variables by array destructuring efficient?

ES6 supports array destructuring which could be used to swap variables in succinct syntax like below, but is this efficient and suggested in performance sensitive code as array processing? Because...

In React ES6, why does the input field lose focus after typing a character?

In my component below, the input field loses focus after typing a character. While using Chrome's Inspector, it looks like the whole form is being re-rendered instead of just the value attribute...

Eslint - `Parsing error: unexpected token =` error for assigned fat arrow / property initializer

I'm using an arrow function and it's complaining about a parsing error: Parsing Error: Unexpected token = However my code is valid (please tell me if i'm mistaken). Additionally, i've set the...

why do functional component in reactjs not have instances?

In React quickstart, it is stated about Refs and Functional Components that You may not use the ref attribute on functional components because they don't have instances: function...

ES6 Modules: Undefined onclick function after import

I am testing ES6 Modules and want to let the user access some imported functions using onclick: test.html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Module...

Proper way of defining functions in ES6?

I'm just wondering how to write ES6 functions properly. I know that it depends on personal preference but what are the pros and cons? function foo() { ... } vs. const foo = () => { ...

ESLint shows error on class instance property initialized to arrow function

maybe similar to https://stackoverflow.com/questions/34244888/how-do-i-configure-eslint-to-allow-fat-arrow-class-methods When class method defined as arrow function Eslint highlight error 'method'...

ES6 template literal with object

I have a function which prints an template literal: function func() { const obj = { a: 1, b: 2 }; console.log(`obj = ${obj}`); } It prints "obj = [object Object]". If I want to log...

Does Object.keys(anObject) return anObject's prototype?

I'm reading Eloquent JavaScript's Map section and I'm having trouble understanding its last paragraph: If you do have a plain object that you need to treat as a map for some reason, it is useful...

Find all matching elements with in an array of objects

I have an array of objects I am searching within the array like this let arr = [ { name:"string 1", arrayWithvalue:"1,2", other: "that" }, { name:"string 2", arrayWithvalue:"2", other:...

React-admin - How can I force the Dasbhoard to ask for login if not authenticated

In the Admin component I would like to have a dashboard like so: <Admin dashboard={Dashboard}> <Resource name="list" list={MyList} /> </Admin> How can I force the dashboard to ask for login...

ES6 array destructuring for specific index

I have an Array const arr = new Array(100). And I set arr[0] = 'A' arr[49] = 'X' When destructuring the 1st element, I can do it like: let [first] = arr How the statement would be like if I want...

I created a "Cash Register" function for Freecodecamp but for some reason the last two tests aren't passing?

I created this function but the last two tests checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE...

"Uncaught SyntaxError: Cannot use import statement outside a module" when importing ECMAScript 6

I'm using ArcGIS JSAPI 4.12 and wish to use Spatial Illusions to draw military symbols on a map. When I add milsymbol.js to the script, the console returns error Uncaught SyntaxError: Cannot use...

Mocha + TypeScript: Cannot use import statement outside a module

I was watching this video in order to learn how to add some simple tests to my Express routes but I am getting all kind of errors while executing a test. The error is: import * as chai from...

Why does my Javascript loop only return the first value?

I'm creating a loop in ES6 which will be used to loop through and output a sequence of 51 images. I've created a for loop, however it only returns the first image, image_0000.jpg, when it...

Why do I need @babel/polyfill at all, using Babel?

I'm learning enormous JavaScript ecosystem and I can't understand the following. Babel is a transpiler, and from the official website: Babel is a toolchain that is mainly used to convert...

How to use template literals of ES6 script

I have been trying to solve a template literal question on hackerrank. It works fine on my local IDE but giving error on Hackerrank IDE. Heres the code two add two number and to print the result...

Next.js dynamic routes with Firestore collection

I'm looking for a way to have a dynamic route that displays for every document in a Firestore collection using Server-side Rendering. For example, a document called foo would exist at test.com/foo...