Questions tagged [ecmascript-6]

1

votes
3

answer
1.1k

Views

react native how to get return from a promise

my problem is i want to get a json from this function but all i get is a only a promise and why i choose this way because in app that i'm working on it works dynamicly but the only place that i see i can put this promise is render() this is my code : var userInfo = (async()=>{ var value = await Asy...
shahabvshahabi
1

votes
1

answer
641

Views

ES6 export an existing object

How come I can write export { function1, function2 }; But I can't write const funcs = { function1, function2 }; export funcs; Isn't it semantically the same thing? Is there any way to export all properties from an object without listing them all one by one? I want to be able to import the module as...
riv
1

votes
0

answer
8

Views

React named presentational / container parent / child components breakdown

Okay, I am trying to make a project using container / presentational components design but I am missing some kind of information or knowledege. What I am trying to do is to render a component based upon it's parent component's type: I have this route: http://localhost:3000/:componentId componentId h...
Martin Fernandez
1

votes
2

answer
34

Views

Add array element during definition based on condition

I define an array like this: [{foo:0}, true === false && { foobar:1}, {bar:2}] My expected result would be that the middle item is not added at all when the middle condition is not met: [ { foo: 0 }, { bar: 2 } ] in fact it adds false as an array item: [ { foo: 0 }, false, { bar: 2 } ] Is there a wa...
Hedge
1

votes
2

answer
1.1k

Views

How do I pass input text t using v-on:change to my vue method?

How can I pass the input value from my html to my vue method called checkEx ist() ? I would like to retrieve that value within my checkExist() method. Could any advice how I can do this? I am still new to vue. HTML: VUE ELEMENT: Vue.component('button-counter', { data: function () { return { count: 0...
ApplePie
1

votes
1

answer
73

Views

reduce function does not initialize accumulator to zero?

reduce does not initialize accumulator to zero? Because the example below happens, I can not understand. const r = (acc, curr) => acc |= (1 0 - ??? And how do I get 1 correctly, as I expect, without doing something like this [0, 0].reduces(r);.
PerduGames
0

votes
0

answer
13

Views

Listen to children events passively with React ES6 (without jquery)

I want to make a kind of accordion expanding panel: but I don't want to have a component for accordion and another for a single expanding panel. my objective is to make something like this: note: I have it working in another environment that uses named event listeners from a specific framework but I...
Marcos Laredo
1

votes
2

answer
173

Views

How to export multiple functions using module.exports in node.js

I'm creating a utilities class to handle some of our common functions to help reduce code copy/past in our modules: I created an exports module. All that's happening here is the export of an object which contains three functions. module.exports = { //retrieve a secret object from the AWS Secrets Ma...
rlcrews
1

votes
2

answer
41

Views

Sending props to a map callback outside the class

I'm working with React. I have a class with a state with an array. The list array, I can make a .map to iterate over it. {this.state.list.map((e, i) => {/*do your stuffs*/} Now, I want to send the logic outside my map, the reason, I have another component that should render the same content but wit...
ValRob
1

votes
2

answer
52

Views

Array destructure with an OR operator issue, Uncaught TypeError: foo is not a function

Return true from function foo and structure it with an OR operator. function foo() { return true; } var [a, b, c] = foo() || []; Why it is throwing an error like foo is not a function.
john33
1

votes
1

answer
65

Views

React / React Native: can't setState using key from previous state?

Struggling to see what the difference is between these two snippets: State is NOT set handleAddItemToCart = (item) => { this.setState((state) => { const { cartItems } = state; item.quantity = 1; cartItems.push(item); return { cartItems }; }); } State IS set return { cartItems: [...cartItems] } It's...
rubie
1

votes
1

answer
127

Views

Javascript nested destructuring syntax [duplicate]

This question already has an answer here: Destructuring deep properties 2 answers While I understand the normal ES6 destructuring syntax, how does the below nested syntax work? const { get, set, computed, Logger: { debug, log } } = Ember;
testndtv
1

votes
3

answer
45

Views

Have clarification about syntax of arrow function while iterating data in react's render function [duplicate]

This question already has an answer here: Curly Brackets in Arrow Functions 2 answers I am just iterating some data from API using arrow function inside render function of react like this. render() { const postItem = this.props.posts.map((post, index) => { {index} {post.title} {post.body} }) return...
Alok Ranjan
1

votes
1

answer
53

Views

Convert JavaScript ES6 function into ES3

I have an array that I successfully transform into a string format with an EcmaScript-6 function. However, how can I do this using EcmaScript-3? The receiving endpoint requires an ES3 function. Original array: formdata: [ 1: {name: 'gender', value: 'F', focus: 0, type: 'radio'} 2: {name: 'firstname'...
Christoph
1

votes
2

answer
47

Views

Is it possible to only update array state of objects?

I was wondering if there is any documentation or reference that could help me to to understand how to update a state of objects array (Without duplicates). My state looks like this: accounts: [ { name: ‘mike’ }, { name: ‘tee’ }, { name: ‘ralf’ }, { name: ‘candy’ }, { name: ‘bon’...
mediaroot
1

votes
2

answer
65

Views

Return child array using Array.Map() in React

My Data from API looks like below, [ { 'id': 1, 'appName': 'string', 'defaultAction': 'string', 'defaultMessage': 'string', 'rules': [ { 'id': 1, 'version': 'string', 'brand': 'string', 'action': 'string', 'message': 'string' }, { 'id': 2, 'version': 'string', 'brand': 'new brand', 'action': 'string...
Maddy
1

votes
3

answer
57

Views

How to use object destructuring spread operator to delete multiple object properties

I am using in my reducers Map/Associative array to store object via string ID. When I need new item into Map I am using this construction rows: { ...state.rows, [row.id]: row } When I need delete item form map by Id I am using this. const { [rowId]: deleted, ...rows } = state.rows; Than in varia...
Ivan Mjartan
1

votes
3

answer
22

Views

JavaScript object property not supported in IE?

I have the following code that works perfectly fine in Chrome etc, but doesn't work in IE 11: var fieldName='UserField'; var fieldValue='update value here...' var obj = { id: 123, [fieldName]: fieldValue }; var message='The field ['+ fieldName +'] will be updated with the value of ['+ obj[fieldName]...
DeclanMcD
1

votes
2

answer
33

Views

How to use template literal on a function paremeter? [duplicate]

This question already has an answer here: Template String As Object Property Name 1 answer I am trying to concatenate a string to shape an object, like this: {addInput.inputs.map((input, index) => ( { startupFourthStepFormActionHandler({ `entreprenuerName-${index}`: e.target.value }); }} value={sta...
Reacting
-4

votes
2

answer
21

Views

concat using rest parameters in es6, javascript

Complete function that convertTemplate() which takes rest parameters as input and returns a concatenated string as input irrespective of the data type passed as argument to the function. sample input - convertTemplate('aa',3) output : aa3 */ let convertTemplate = (...input)=>{ };
Mandip Kaur
0

votes
1

answer
13

Views

Is there any way to call function with parameters In react-native?

i want to know how to call function with parameters in arrow function this is my code export default class App extends Component { state = { number: 1 }; change_number = (type) => { if(type === minus){ this.setState({ number: this.state.number - 1 }) }else{ this.setState({ number: this.state.number...
doso
0

votes
0

answer
4

Views

Mocking classes with Jest

Given I have a class that calls a function doStuff like so: const myService = require(`./myService`), service = new myService(); exports.doStuff = async (callback) => { try { const data = await service.doOtherStuff(); //I want to mock this return callback(null, data); } catch (err) { callback(new Er...
Tikkes
11

votes
5

answer
434

Views

Using a map function on a 'Map' to change values

I can use a Map and then set values: const a = new Map([['a', 'b'], ['c', 'd']]) Now if I want to apply a function to all values in a functional way (without for ... of or .forEach), I thought I could have done something like this: const b = a.map(([k, v]) => [k, doSomethingWith(v)]); But there is n...
rap-2-h
0

votes
0

answer
7

Views

cannot pass param to the finction param of addEventListener

I have the following function: export function myoutsideClickHandler(menuRef) { console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%'); console.log(menuRef); document.addEventListener('click', (menuRef)=>test1(menuRef), false); } I can see that menuRef is printed and has value. So far so good. Now in test1 funct...
Hamed Minaee
0

votes
2

answer
22

Views

I cannot get the accurate height of an element with pure javascript

I use the following function to get the full height of an element: outerHeight1=(el)=> { let style = window.getComputedStyle(el); return (parseInt(style.getPropertyValue('height').replace('px',''))+ parseInt(style.getPropertyValue('border-bottom-width').replace('px',''), 10)+ parseInt(style.getPrope...
Hamed Minaee
1

votes
0

answer
10

Views

deconstruct and convert in react

My issue is simple. A react component receives props and I'm deconstructing it like this: const {ram,core} = this.props but I want to divide the 'ram' value by 1024! of course I could go with let {ram,core} = this.props ram/=1024 but can I do it in one line and use const too?
Amir Shahbabaie
2

votes
2

answer
42

Views

How to apply nested sorting in javascript

I have below array of objects in javascript [ {'name' : 'Ram', 'age': 10 , 'city' : 'a'}, {'name' : 'Shyam', 'age': 5 , 'city' : 'a'}, {'name' : 'Aditya', 'age': 10 , 'city' : 'b'}, {'name' : 'Aditya', 'age': 5 , 'city' : 'a'}] Now I am in need to apply nested sorting. A user could sort the above c...
Kgn-web
0

votes
1

answer
19

Views

DidComponentUpdate Infinite Loop React Native

Why DidComponentUpdate is on Infinite Loop? I trying to get some data from an Api When user changeText on Input componentDidUpdate(prevState){ if (prevState.userinput !== this.state.userinput){ fetch('https://'+this.region+'.api.riotgames.com/lol/summoner/v4/summoners/by-name/'+this.state.userinput+...
Josemar Henrique
1

votes
1

answer
39

Views

Getting Javascript To Pass Variable By Value

I have two while loops running simultaneously with observables, the methods look like this (I've taken out the names for brevity): initiateGraph(fromDate: Date, toDate: Date) { const graphParts = zip( this.dothefirstthing(fromDate, toDate), this.doanotherthing(fromDate, toDate) ); } both methods tak...
Adam Weitzman
0

votes
3

answer
30

Views

What exactly is an object? [JavaScript]

Ive learned on MDN that an object is something with properties and method and that mostly everything in JavaScript is / can be treated as an object. Everything mentioned in the previous sentence makes it hard to tell what an object is. Some articles say that objects are just data containers others s...
iamlearningtocode
0

votes
0

answer
11

Views

what's the meaning of “!” in 7.2.14 Abstract Equality Comparison of ecmascript spec

i'm confused a bit that in the Abstract Equality Comparison Section as below: The comparison x == y, where x and y are values, produces true or false. Such a comparison is performed as follows: If Type(x) is the same as Type(y), then Return the result of performing Strict Equality Comparison x === y...
leo
1

votes
1

answer
4.3k

Views

How to fix Property binding ng-forOf not used by any directive on an embedded template? [duplicate]

This question already has an answer here: Can't bind to 'ng-forOf' since it isn't a known native property 9 answers I'm trying to set-up a simple ng-for to loop over a list of project in angular but got stuck with it. I already tried the solution in Angular2 exception: Can't bind to 'ngFor' since i...
Édouard Lopez
0

votes
1

answer
20

Views

How to compare two arrays, delete element on the first that's missing in the second and push the difference

I have two arrays with 'tickets' that I need to update every 3 seconds, the problem is that for animation reasons, I can't simply overwrite the first array to be just like the second. Like this: let array_1 = [1, 2, 3, 5]; //diff 3, 5 let array_2 = [1, 2, 6, 7]; //diff 6, 7 What I need is to compare...
Platiplus
1

votes
3

answer
87

Views

How to transform an object into an array of objects?

I am looking for a way to transform an object into an array of objects, and remove the first unique key. How can I make this: {f56hdhgf54: {name: 'Sam', age: 34}, h65fg9f7d: {name: 'John', age: 42}} into this: [{name: 'Sam', age: 34}, {name: 'John', age: 42}] so I can .map through it like this: resu...
allegutta
1

votes
2

answer
543

Views

How to wrap render Function in React?

I have already wrap the render function in ES5 like: var Test = React.createClass({ componentDidUpdate:function() { this.refs.table.cleanSelected(); }, getInitialState: function() { return getItemPropertyData(); }, render:ExceptionInterceptor('Test','render',function(){ return( Test ) }) }); My Exce...
Dhaval Patel
2

votes
4

answer
23

Views

destructing an object being function's argument with default property

I want to pass an object as an argument to the function. If property 'prop' of this object is undefined, it should be initialized by default value. How to do it using modern JS? I expect something like this: const fun = function(options = { prop: 'default'}) { console.log(options.prop)} fun({a: 'x'...
Asker
1

votes
8

answer
1.5k

Views

How to check if a specific object already exists in an array before adding it

I have this array: [{'name': 'Olvier', 'id': 123 }, {'name': 'Olvier', 'id': 124 }] Now my goal is to prevent adding the same object again to the array: {'name': 'Olvier', 'id': 123 } Is there a Method to do this?
olivier
1

votes
1

answer
1.2k

Views

module.exports Cannot set property of undefined

I am trying to move all react components to separate repo so that they can be shared. I am getting the above error ui-react/index.js 'use strict'; import Button from './components/Button/Button'; module.exports.Button = Button; FileB import {Button} from 'ui-react'; When i do this i get an error...
aWebDeveloper
1

votes
1

answer
19

Views

Remove duplicates from nested map objects javascript

I'm displaying data on a grid using a nested map which looks like { this.state.rows.map((qc) => qc.BinsByDayByOrchardsQCs.map((qc2) => qc2.BinsByDayByOrchardsQCsDefects.map((qc3) => {console.log('results', qc3.Defect)} {qc3.Defect} ) ) ) } Which returns data that looks like this results Scuff resu...
invrt
3

votes
8

answer
77

Views

Create array of objects by key from array of objects

There are a lot of questions like this on here, but I couldn't find one that matched my needs. I'm looking for a relatively simple solution on how to stack objects in an array into new arrays based on a key. In the example data we're grouping the objects by their 'ship' key. Original data: var myObj...
Ian Gray

View additional questions