Questions tagged [ecmascript-6]

The 2015 version of the ECMAScript specification, now a standard (ECMAScript 2015). Only use this tag where the question specifically relates to new features or technical changes provided in ECMAScript 2015.

Filter by
Sorted by
Tagged with
0
votes
2answers
29 views

Is it okay to do axios call in setInterval?

I am aware that it might have some kind of ram leak or something for constantly calling on API for status. I am going to do a live status update when you login into third party application. I have all ...
0
votes
0answers
10 views

Importing nested JavaScript ES6 modules to a module created from a string of code

I am getting errors trying to create a JavaScript ES6 module from a string of code when it contains imports to other modules. Here is what I have tried so far without success: (async () => { ...
0
votes
1answer
23 views

How to change input value which is coming from props in React?

I want to create a number of dynamic inputs in React, my code looks like: import React, { useState } from "react"; import "./styles.css"; const style = { display: "flex", justifyContent:...
-1
votes
4answers
45 views

How do I overcome a “function is not defined” error when loading an external .js file?

I'd like to create a JS plugin (with ES6) so that it can be called from an HTML file, like this: <div id="emails-box"></div> <script src="emails-box.js"></script> <script&...
1
vote
1answer
32 views

If/Else Statements, and unintended String Concatenation

novice programmer here. I'm currently working on a project that pumps integers into a text field, yet decided to run the array through a for loop which shoves each item into a string that's more ...
0
votes
0answers
13 views

Javascript/JQuery/Output Different output between promise and await when calling endpoint using JQUERY.get

I'm getting some mock data from a mock endpoint, using JQuery and promises. Just for the sake of it, I want to try and make it work with async/await. I think I managed to find some code that works, ...
0
votes
1answer
46 views

find first index of array in string javascript [duplicate]

There is a string variable that has a path like /app/something/xx/4/profile besides there is an array of string like ** const arr=[ {name:'xx',etc...}, {name:'yy',etc...}, {name:'zz',...
-1
votes
2answers
30 views

Javascript Promise: can't get the return value out of my function

I can not get the return object out of my function, so I can reuse it in the next function which should be called by my promise.then(). Struggling with researching, and can not find the solution. ...
0
votes
3answers
51 views

Filter javascript array with subarray childern and return parent

Thanks in advance. Iam having the below array and am trying to work out with array filter in javascript. [{ID: 16,ItemName: "SomeData 1", children : []}, {ID: 19,ItemName: "SomeData 2", children : [{...
0
votes
2answers
27 views

How to create a dynamic multi dimensional array based on given input number such that every array should pushed to its nested array?

I have created an empty string and created a deeply nested array as a string "[[[]]]" then I applied eval function on it to convert it into an array. Is there any better approach than what I have done?...
0
votes
2answers
55 views

Updating the object based on the presence of the key else form a new object : Javascript

Have an object with following format: let obj = { p2: { p21: [ { key1: "val1", value1: "val2" }, { prop: "test", value: "dummy" } ] ...
1
vote
0answers
29 views

npm run throws errors for ECMAScript 6 code despite installing es6 in the project

I am working on a project that uses node, where a lot of modules are in turn dependant on modules that use ECMAScript 6 code. For example, some modules use let, some use => for function definitions,...
0
votes
1answer
20 views

Best devenv for Progressive Web Apps [closed]

Please suggest the best development environment for PWAs. I will be writing in ES6 strict mode, with lots of DOM manipulation. I have a fairly large and complex project, so I need tools for ...
1
vote
4answers
44 views

Imported function is undefined

I'm a little unfamiliar with ES6, so I'm not entirely sure what my issue is here. I have the following code; const isUsernameTaken = username => { console.log(username); } exports = { ...
0
votes
1answer
32 views

how to cancel timeout when next calling arrives in useEffect react

I want to clear or cancel the timeout when next calling arrives. React.useEffect(() => { // set timeout to control unwanted searches setTimeout(doSearch, 300); return () => { ...
0
votes
0answers
23 views

highchart events by arrow function [duplicate]

I work on angular project. I use highchart and want to declare a label-click event for xAxis. In the callback function In need to use other services that my component gets as a dependency. For use it ...
0
votes
1answer
39 views

How to restrict html number input to have only numbers with only one dot allowed?

I have pattern for numbers and decimal. ^\\d{0,16}(\\.\\d{0,6})?$ but this pattern allowing to enter multiple dots. How not to allow multiple dots ?
-1
votes
3answers
38 views

Node.js unable to import ES6 module

I'm trying to separate my routes to a separate module in routes.js and then importing in app.js. I'm getting a lot of errors in the console. internal/modules/esm/default_resolve.js:96 let url = ...
1
vote
2answers
51 views

Filter tasks doesn't work - Todo list with MVC pattern using es6 classes

I'm trying to write a todo list project with pure JS using MVC pattern. It's my first project with MVC and I have a real problem that I can't solve. I have three buttons, each button gets a value as ...
0
votes
1answer
40 views

Why does 'useState()' appear not to be working?

I have some object properties that I need to generate dynamically. (The object is the initialValues object for a Formik component.) When I try to update the formValues inside a useEffect() call, they ...
-3
votes
1answer
29 views

Unable to delete value from set? [closed]

let obj = { name: 'ajay' }; let obj1 = { name: 'sham' }; let newSet = new Set(); newSet.add(obj); newSet.add(obj1); console.log(newSet.has('name')); console.log(newSet.delete('ajay'));
0
votes
0answers
39 views
+400

Unable to test post methods with Jest due to error can not read mockImplementation of undefined

I have an api service where I have different methods to make calls to the APIs. I've successfully tested all of the GET requests but I am having troubles testing the POST requests. This is the method:...
0
votes
0answers
35 views

Flood Fill algorithm canvas

I am using floodFill algorithm, but it very slowly. For example, I have canvas(512px x 512px) and to fill whole canvas I need 6 seconds. Can you help me to improve my implementation? I'm using ...
2
votes
1answer
41 views

Why doesn't the generator return the following value?

For each call to the "loop" function, I try to return a new value of the "c" property from the "test" object, but for some reason, I get the same value of every function call. 1 call: {value: {a: 1},...
1
vote
0answers
15 views

es6 import syntax in node console not working

I'm getting the following error trying us the es6 import syntax inside the node console. import Dog from './lib/Dog.js'; Thrown: import Dog from './lib/Dog.js'; ^^^^^^ SyntaxError: Cannot use ...
0
votes
4answers
57 views

React Hook useEffect issue with setState

I am using useState which has 2 array imageList and videoList and then in useEffect hook i am using forEach on data then if type is image then push to item to image . But at last i am not getting ...
-4
votes
1answer
73 views

ES6/React adding object to array

Somewhere in the code lies a flaw if someone could spot it it I would appreciate help thank you. Step 1. react form to add a record to the state containing two variables [email & name] ...
0
votes
3answers
37 views

Passing template strings into array.filter operation

I have some code that compares two arrays and filters data, that looks like this: const recordsToUpdate = await sourceArr.filter(e => targetArr.find(obj => obj.id === e.id_number) !== undefined)...
0
votes
0answers
30 views

Protractor - Must use import to load ES Module

Using protractor and trying to switch to using es6 import instead of commonjs require approach I changed package.json and added (in the top section) "type": "module" I renamed my two app files from ....
-1
votes
0answers
12 views

Javascript ES6 access static property of sub class from parent class [duplicate]

I have a class called BaseService and I want to extend multiple sub-classes from this. Like MyService1, MyService2 and so on. Each sub-class has a static property called _manifest. I would like to put ...
0
votes
1answer
26 views

Classes and constructor in Es6 program

Create a class car with a constructor function which accepts 2 parameters (name and distance). Include a prototype method in class, which returns a message(msg) "car name(name) had travelled for ...
0
votes
1answer
41 views

Elegant way to do multiple parameter filter for client-side search

So, say I have an object that looks like the following: const DEVICES: { mac: string; name: string; ip: string; type: number }[] = [ { mac: 'xx:xx:xx:xx:xx', name: 'something', ip: 'xx....
-2
votes
2answers
31 views

Test.js is not passing the destructing ES6 program

I am trying to write a simple destructure program of assigning array value in hackerrank but everytime I am getting an npm error with no error statement (only this- that file is a common js module) ...
-1
votes
1answer
15 views

Issue with imports in React/Redux application

I'm using a Rails-style organization for a React/Redux project but I'm having an import issue that I can't figure out. I have a constants directory with a module index (index.js) that looks like this:...
0
votes
1answer
71 views

Most efficient way to return a nested array that includes a string (JavaScript)

I'd like to know if there's a more efficient method of accessing a nested array based on a matched value instead of using 'forEach' or a 'for' loop. This is what I have at the moment: var a = [ ...
0
votes
1answer
28 views

Get array from nested json value objects

I've been searching an answer for that but didn't found it. I have an array like: const data2 = [{ "abc":{ companyCity:"Cupertino", conpanyName:"Apple" } }, ...
0
votes
3answers
38 views

Comparing Two Arrays with Array.filter and Pushing to New Arrays Based on Common Values

I am trying to use array.filter() to compare two arrays and separate out values that the two arrays have in common, based on a certain property (id), vs. values they don't have in common. The common ...
0
votes
0answers
11 views

binding event listeners to ES6 objects [duplicate]

I have a class for a dom element: class Comment{ constructor(id, node, text){ this.id = id; this.node = node; this.text = text; this.element = document.createElement('div'); ...
0
votes
0answers
41 views

ES6 : Output contains undefined along with results and I cannot understand why? [duplicate]

When ever I am trying to write a simple arrow function in ES6, I get the output right but also get an undefined in the result. const greet = (name) => { return `Hello ${name}`; }; console.log(...
0
votes
3answers
26 views

How i can do that if inputs are empty nothing will happen

How can i do that if two inputs are empty nothing will happen now it work just when one of them are empty. let inputs = document.querySelectorAll('.input'); let btn = document.querySelector('....
0
votes
1answer
46 views

Better way to declare multiple variables assigned to a function in Javascript

I'm looking for a shorter way to declare these variables: const [nav, header, footer] = [getProps(data, ['nav']), getProps(data, ['header']), getProps(data, ['footer']) ]; I've tried this but it ...
0
votes
1answer
14 views

Not able to use feather-icons for divs constructed in JS files

I am using feather icons in a vanilla js project. When I am declaring the script feather.replace() inside the html body, the icons are coming correctly. However, I am creating certain div dynamically ...
0
votes
2answers
31 views

Disable prettier for a single file

I need to disable prettier for single file (API URLS file) in my project in Vs-code. actually I need each API and its URL be to in one line , but prettier break them in two lines. before export ...
5
votes
1answer
54 views

React js rename & destructure array length

I have a reduce function like below: let el = scopes.reduce ((tot, {actions}) => tot + actions.length, 0); I tried to transform it like this, but it seems that it is not the correct way: let el =...
1
vote
1answer
59 views

Key is defined but it warns “Each child in a list should have a unique key prop”

although I defined a key for SearchDropDownItem it shows a warning component DropDown filteredItems.length > 0 ? ( filteredItems.map(item => { return ( <...
-2
votes
1answer
32 views

When I try to add a question in the App it returns me an Error. What's the problem?

I'm finishing debbuging an App I've built for a React-Redux course I'm doing. And in the App, I'm supposed to add questions in a form just like the following: But, when I click submit, it returns to ...
0
votes
3answers
54 views

refactor map, reduce and double for loop - javascript es6

I have a JavaScript object, lets say parentObj. How can I improve the below code. I have a reduce, a map and a double for loop. [ { NAME: 'SOMENAME', ID: '1', FROM: '20191223'...
-1
votes
2answers
36 views

How to efficiently construct new object array using unique values from arrays of children inside an array of parent objects

The need is to take objects like this: [ { "first": { "children" : [{ "name": "abc", "detail":"123"}, { "name": "def", "detail":"456"} ] }}, { "second": ...
0
votes
3answers
55 views

Using ES6 spread operator on an object that is returned from a function

I am using a function to convert hex codes to rgb values, it's one I found on this site and all is working perfectly. The function takes in a string as an parameter, and returns an obj with r,g,b ...
-2
votes
0answers
38 views

save an item of an array to update a state

I have a select inside render where I display the firstnames only <FormGroup> <Input type={'select'} name={'firstNameSelected'} value={this.state.firstNameSelected} ...