Questions tagged [ecmascript-2016]
Questions about new features specified in the ECMAScript 2016 specification.
486
questions
0
votes
2
answers
52
views
sort array of objects by order of the property in a fixed format
I need to sort an array of object by property with the following order.
For the first item in the list: it is either Camel or Absolute
For the second item in the list: it has to be Dream,
For the ...
0
votes
0
answers
12
views
how do i export mysql createPool( in node.js using ES7 format
Trying to learn how to export in Node.js using ES7 format
Specifically mySql and getConnection() {
FILE: connection.mjs file.
import mysql from 'mysql';
var ip="";
// i had ...
0
votes
1
answer
58
views
Javascript - Remove items that are duplicates from array and return an array with duplicates and other one with all other items [duplicate]
I wanted to run a filter or reduce operation on an array and remove all duplicate items from the array based on an attribute like 'name' in this example. The examples I see are iterating through the ...
1
vote
0
answers
32
views
check attribute with value 0 exists or not returns false though it should return true as it exists [duplicate]
I am trying to check if an attribute is in a json file or not but the attribute has a value of 0 so the following
status.bytes_read
returns false though it should return true as it exists
what is the ...
-2
votes
2
answers
97
views
How to replace value in javascript or ecmascript?
I need to replace All in s3data Emp_Id with the response data's values(expected output appended), ignore 0 and 1 in response they are not required.
S3data is json data
I can't use inbuilt function ...
1
vote
1
answer
552
views
Error: listen EADDRNOTAVAIL: address not available 127.0.0.0:5173
after install project with tailwind with the command
npm create vite@latest my-project -- --template react
and after config tailwind, I tried to run my project but I got this error.
I tried to install ...
3
votes
1
answer
210
views
How does a JavaScript developer find implementing classes of an interface?
I am learning JavaScript, and I am coming from Java.
A Java developer can easily evaluate the usefulness of an interface, because all known implementing classes are documented. Please click here to ...
2
votes
2
answers
58
views
Get matching items by comparing two arrays
I have an array of objects that look like this
const input = [ {id : "1" , text: "ABC", value: "abc" }, {id : "2" , text: "DEF", value: "def"...
2
votes
0
answers
102
views
How to make vitejs compile class private fields to legacy code?
I am using vitejs and typescript and I want to set the compile target to es2016, but it seems that, the class private fields aren't be compiled.
class Task {
#prepare() { // here should be compiled....
0
votes
1
answer
50
views
How does the setTimeout() in javascript knows how many times to loop inside of a for loop?
for (var index = 1; index <= 3; index++) {
setTimeout(function() {
console.log('after ' + index + ' second(s):' + index);
}, index * 1000);
}
output:
after 4 second(s):4
after 4 ...
0
votes
1
answer
429
views
How to use await with setTimeout [duplicate]
// getData() function is returning null right now , but Actually I want to return a value after 1.5 seconds
showData = (data) => {
console.log("showing" , data)
}
...
-2
votes
1
answer
47
views
How do I do "Reverse destructuring"
We all know about destructuring objects in ES6+
const myObject = {name: 'John', age: 30, eyeColor: 'brown'}
const {name, age, eyeColor} = myObject
... is there a "cleaner" way to do the ...
0
votes
1
answer
182
views
how ES7 import module's object in Node.js
var GoogleStrategy = require('passport-google-oauth20').Strategy;
How can I use ES2017's way to write it? I try
import GoogleStrategy from ('passport-google-oauth20').Strategy
But it couldn't work
...
1
vote
2
answers
37
views
How to map an array base on other arrays without nested looping - JS/TS, ES6(7)?
I have 2 arrays.
const history = [
{ type: 'change', old: 1, new: 2 },
{ type: 'change', old: 3, new: 4 },
];
const contents = [
{ id: 1, info: 'infor1' },
{ id: 2, info: 'infor2' },
{ ...
0
votes
1
answer
89
views
Javascript / ES7: do I need to bind 'this' in my particular Web Component class constructor? [duplicate]
My code works, but I was taught to bind 'this' to the event listener function. In my web component class constructor, I have a button in the shadow root. In the constructor I also added the click ...
0
votes
0
answers
109
views
NodeJS : Trouble with ES6, import and export
I'm quite new in the NodeJS world. I have a question :
I'm trying to put a unit test with Jest in order to test this 'Service' with the 2 functions as below in the quotationService.js file :
export ...
-1
votes
1
answer
483
views
Adding 1 additional object to the map function ES6
I have a code in place which looks like this -
mapFn={response => (response.data && response.data.map(secret => ({
label: secret.secretName,
value: ...
1
vote
3
answers
41
views
Coercion in JavaScript - Abstract Methods
I have recently started learning more about coercion in Js and I have been going through the ECMAScript documentation for knowing more about it and how different cases are handled in Js.
While doing I ...
0
votes
3
answers
36
views
Filter Array and Array within
I'm trying to filter an array of objects based off a property and also filter an array of objects within. Can I use filter within a filter to loop through and reduce the second array?
Something like ...
3
votes
1
answer
84
views
Does ECMAScript Regular Expressions match its syntax characters?
I'm referring to ECMAScript regular expression syntax defined in https://tc39.es/ecma262/#sec-regexp-regular-expression-objects.
I checked how the following pattern matches in a regular expression via ...
-2
votes
2
answers
79
views
How to simplify object
I have an issue here where the code is quite heavy and quite hard to read imo.
I've simplified the code as much as I can but I was wandering if there's a way to simplify this code even further? Or ...
3
votes
0
answers
1k
views
unhandled promis and node js upgrade to 16 though I use try catch
I am facing a very strange issue. As soon as I updated my node to node 16 from 14 my tests stopped working and I get a complain like this:
Error:
at /src/api/v1/datastore/SearchesDatastore.ts:109:...
3
votes
0
answers
659
views
use require() in .mjs bundles - Angular 13
I recently upgraded my project to Angular 13, I noticed that the new ng-packgr 13 bundles in .mjs extension by default. I have lots of code that uses require() to import some static assets and files. ...
1
vote
1
answer
2k
views
Import external static file in webpack bundle
How can I import an external file (config.js) from within a webpack bundle?
I have the following file-structure for local dev:
/dist/
/index.html
/plugin.js
/src/
/index.ts
/config.js ...
2
votes
2
answers
536
views
Why new Date("1651214829629") show invalid date?
When I run this code in the chrome console, it shows the following:
>new Date("1651214829629")
Invalid Date
>new Date(1651214829629)
Fri Apr 29 2022 14:47:09 GMT+0800 (中国标准时间)
>...
-1
votes
2
answers
280
views
How to compare two objects and change the key name?
compare headerObj(field_key) and dataObj(key) and form the result with label from headerObj
const headerObject = [{
label: 'Code',
field_key: 'code'
},
{
label: 'Worked Accounts',
...
1
vote
1
answer
853
views
React router is not working. It is showing nothing but a blank screen
I am trying to make a simple react-router. But it's not even working. If I don't include the <Routes> tag the page is blank. After including the <Routes> tag it is also not working. Please ...
1
vote
0
answers
134
views
Angular - cannot find name 'window' / 'document' / 'localstorage'
I've tried to update packages in an angular project but I'm getting many errors like "Cannot find name 'window'".
My tsconfig.json looks like this:
{
"compileOnSave": false,
&...
0
votes
0
answers
34
views
Can I use class field without declaring them? [duplicate]
Can I have a class like this?
class Human {
constructor(name) {
this.name = name;
}
someMethod() {
this.hasBrain = true;
console.warn(this.hasBrain);
}
}
This is working and not ...
0
votes
0
answers
838
views
How to check location setting in real time in React native
I am working on an application where I am checking that user is off or on their location. I am using react-native-location-enabler package to check the location setting, it works fine but the problem ...
0
votes
2
answers
392
views
Is there any way to run asscroll package in react project?
I was searching a few libraries for scroll animations and I found a very good npm package called @ashthornton/asscroll and I wanted to use the same on my react project.
But I am not been able to ...
0
votes
0
answers
40
views
How to update a specific index of an array when using spread operator [duplicate]
This is a more of a can it ever be done even with a parser like babel or anything type of question which i believe is allowed in SU. All just to make my code cleaner for Reducer and State in general; ...
-4
votes
1
answer
133
views
How can I sum object values by array data using ES standard? [closed]
I have an array of objects. Each object has a "tag" property with an array list. The values in this list repeat from object to object. I would like to sum up "cost" and "...
0
votes
1
answer
157
views
Typescript import syntax problems
I'm new to Typescript and I've problems when I use import/export syntax in the browser.
The terminal/compiler doesn't throw any kind of error. But google's console says:
GET http://127.0.0.1:5500/...
0
votes
1
answer
320
views
React typescript error: Element implicitly has an 'any' type
I am a beginner at typescript and I am using it in reactjs but I am getting errors. Could someone please help me with how to resolve this issue? Element implicitly has an 'any' type because expression ...
0
votes
1
answer
28
views
How to render propeties with nonzero values inside template strings
I am actually trying to render an HTMLElement using template strings. The function goes like this
function renderContent(){
return `<div class="card">
<span>...
1
vote
2
answers
461
views
Using JavaScript count the number of elements equal to or higher than the index in a loop
I'm working on a JavaScript function that can create an authors- H-Index. H-Index is the highest number of publication an author has written with just as many citations in other articles. I have
let ...
1
vote
0
answers
24
views
How to merge objects preserving unchanged properties [duplicate]
I have a complete config object and another object that can be partially filled.
When merging them, I need the unchanged settings to remain.
let defaultConfig = {
locale: 'en',
messages: {
...
4
votes
1
answer
228
views
Where in the ECMAScript specification can I find the reason about why {} !== {}?
In JavaScript We all know that {} !== {} - they are different objects allocated on heap. But I was trying to find the reason at the language specification level.
at https://tc39.es/ecma262/#sec-...
0
votes
0
answers
576
views
export default connect( mapStateToProps )( withRouter( app) ) not passing mapStateToProps to next component
I want to pass mapStateToProps value to next component while using withRouter so that i can maintain this.props.history also.
Here is my code.
import React from 'react';
import { connect } from 'react-...
0
votes
3
answers
2k
views
Keyboard pushing everything up in React Native app
I have a simple auth form in my react-native app, but everytime the software keyboard appears, whole screen moves up and squishes everything together. I am desperate and unable to do anything about it,...
-1
votes
3
answers
52
views
Porblem on Getting Array Inside of Array
I have a problem on an object inside of an array and I wanted to display only that as an array.
data1
const data1 = [
{
"id": "01",
"info": "fefef",
...
-1
votes
1
answer
3k
views
src\components\Home.js Line 6:10: 'Container' is not defined react/jsx-no-undef
import React from 'react'
import styled from "styled-components";
function Home() {
return (
<Container>
home
</Container>
)
}
export ...
0
votes
0
answers
432
views
Concurrent HTTP requests with limit in pool and with exceptions
I have been looking for the perfect library that does async requests in batched pools. I have looked at p-limit, tiny-async-pool and others but they all have the same limitation for what I am trying ...
0
votes
1
answer
125
views
Ts destructuring array of string to be a parameters
Hi I have an array of keys
Ex1:
const arrWithKeys = ['a','b','c']
I want to use them as parameters because I don't want to write them multiple times, there is a way to achieve it?.
Ex2:
const [......
0
votes
0
answers
145
views
Material ui datatable filter by selected rows
I'm using muidataTable to display some data,and i have to calculate a value that requires filtering by selected row and reducing the array.
My code looks like:
Array.filter(//mylogic(e)=> e....
1
vote
0
answers
638
views
How to watch an imported variable in Vue
I have a file called get.js with an exported function and an exported var within it:
var a = false
export function get(url) {
return new Promise((resolve, reject) => {
const xhr = new ...
0
votes
1
answer
146
views
Having variables in the constructor vs in the actual class?
The first of the below code examples is what I am doing today, where I initialise the global variables in the constructor.
But would there be any harm in moving the global variables out in the class, ...
0
votes
0
answers
161
views
How do I inherit keys in parent class dictionary in child classes
I am trying to write Cypress UI test automation in which I am capturing UI elements on each webpage in its own class. I have two classes corresponding to different webpages:
class WebPage1 {
...
0
votes
1
answer
57
views
How do I use one function for 2 variation of components?
Javascript newbie here. I have to write this using plain old Javascript. I have 2 inline edit components, only difference is that one uses icons instead of buttons. The issue I have is I wrote 2 edit ...