Category "ecmascript-6"

Defer execution for ES6 Template Literals

I am playing with the new ES6 Template Literals feature and the first thing that came to my head was a String.format for JavaScript so I went about implementing

Replace element at specific position in an array without mutating it

How can the following operation be done without mutating the array: let array = ['item1']; console.log(array); // ['item1'] array[2] = 'item2'; // array is mut

React: Updating state when state is an array of objects

I have an array of objects in state: this.state = { items: [ {id: 1, someattr: "a string", anotherattr: ""}, {id: 2, someattr: "another string", anot

Winston 3.0 colorize whole output on console

I am developing a Node.js application, using babel-cli as an ES6 transpiler and I am using Winston 3.0 as my logging service. Question: I want the whole output

Winston 3.0 colorize whole output on console

I am developing a Node.js application, using babel-cli as an ES6 transpiler and I am using Winston 3.0 as my logging service. Question: I want the whole output

React: Updating state when state is an array of objects

I have an array of objects in state: this.state = { items: [ {id: 1, someattr: "a string", anotherattr: ""}, {id: 2, someattr: "another string", anot

ES2015 import doesn't work (even at top-level) in Firefox

These are my sample files: <!DOCTYPE html> <html> <head> <title>Test</title> <script src="t1.js"></script> </h

How to test if an object is a Proxy?

I would like to test if a JavaScript object is a Proxy. The trivial approach if (obj instanceof Proxy) ... doesn't work here, nor does traversing the prototy

How to tell typescript, that process is not undefined?

In the following line of code: internalWhiteList = process.env.INTERNAL_IP_WHITELIST.split( ',' ) I get an error saying, Object is possibly undefined. env va

Template literals with nested backticks(`) in ES6

How can I write a template literal in ECMAScript 6 that will contain backticks(`) in and by itself, (i.e. nested backticks)? For example: var query = `

ES6 modules - imported constants undefined if not in React component

The only similar question I have found is this one but I can't see how would I have caused a circular dependancy in this case: I have a file exporting constants

Why ngOnChanges() does not trigger when @Input() update the data Angular 8?

parent.component.html <parent-comp [data]="mydata"> </parent-comp> parent.component.ts this.service.abc$ .takeUntil(this.ngUnsubscribe.asOb

Shallow-clone a Map or Set

How do you shallow-clone a Map or Set object in JavaScript? I want to get a new Map or Set that has the same keys and values.

How do you import a javascript package from a cdn/script tag in React?

I'd like to import this javascript package in React <script src="https://cdn.dwolla.com/1/dwolla.js"></script> However, there is no NPM package,

ExpressJs is return error `ERR_MODULE_NOT_FOUND` if I import the file without `js` extension

I build a expressJs app by ES6 and I got the below error: (node:4132) ExperimentalWarning: The ESM module loader is experimental. internal/modules/run_main.js:

How to scroll to an element?

I have a chat widget that pulls up an array of messages every time I scroll up. The problem I am facing now is the slider stays fixed at the top when messages l

How to omit specific properties from an object in JavaScript

Is there a clean way to return a new object that omits certain properties that the original object contains without having to use something like lodash?

Node v13 / Jest / ES6 — native support for modules without babel or esm

Is it possible to test ES6 Modules with Jest without esm or babel? Since node v13 supports es6 natively have tried: //package.json { … "type": "modu

babel-node is not recognized as an internal or external command, operable program or batch file

When I try to run a JS file by babel command it is showing: "babel-node is not recognized as an internal or external command, operable program or batch file

How can I select only a few fields when destructuring a JavaScript object? [duplicate]

I can't seem to remember how to write this destructuring pattern, could you please help me? Let's say I have an object like this: { id: 'po_