spread-syntax Questions

25

Solved

What does the ... do in this React (using JSX) code and what is it called? <Modal {...this.props} title='Modal heading' animation={false}>
Timberlake asked 25/6, 2015 at 11:21

49

Both Object.assign and Object spread only do a shallow merge. An example of the problem: // No object nesting const x = { a: 1 } const y = { b: 1 } const z = { ...x, ...y } // { a: 1, b: 1 } Th...
Analog asked 14/1, 2015 at 6:7

3

Solved

I am using node and i have used . babel-node "start": "nodemon --exec babel-node --presets es2015 index.js" My spread syntax is not working as expected. Here is my code. export const login =...
Exertion asked 1/3, 2019 at 19:38

6

Is there any implementation in C# like JavaScript's spread syntax? var arr = new []{"Hello", "World"}; Console.WriteLine(...arr); 3rd party edit Using a method public void gree...
Suckle asked 6/10, 2016 at 2:45

6

Solved

I was trying to understand what is the difference between spread syntax vs slice method in the following approach. suppose I want to make an actual copy of an array, I can probably easily do it us...
Overstuffed asked 3/7, 2018 at 23:53

4

Solved

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 su...
Politicking asked 11/5, 2016 at 2:13

5

Solved

From mdn: Spread Syntax Note: Typically the spread operators in ES2015 goes one level deep while copying an array. Therefore, they are unsuitable for copying multidimensional arrays. It's the s...
Taub asked 15/4, 2017 at 2:55

15

Solved

I am trying to create a deep copy map method for my Redux project that will work with objects rather than arrays. I read that in Redux each state should not change anything in the previous states. ...
Candracandy asked 16/7, 2016 at 21:57

6

Solved

I want to perform Destructuring in php just like in javascript code below: [a, b, ...rest] = [10, 20, 30, 40, 50]; console.log(a,b,rest); Output: 10 20 [ 30, 40, 50 ] How can I preform that opera...
Dermatologist asked 3/3, 2023 at 5:58

4

Solved

I understand spread syntax makes a shallow copy of objects, i.e., the cloned object refers to the same reference as the original object. However, the actual behaviour seems contradicting and confus...

9

Solved

I am running into an error that says Type must have a '[Symbol.iterator]()' method that returns an iterator. It hopes on the demarcated line: class Test { private async do() { const done = [...(...
Genro asked 8/5, 2018 at 13:11

3

Solved

I have a function that adds a key to incoming object, but I have been told to use the spread operator for that, I have been told that I can use the spread operator to create a new object with the s...
Rostellum asked 26/3, 2018 at 12:22

4

Solved

I'm trying to convert a data structure like this: data = { 0:{A:a}, 1:{B:b}, 2:{C:c}, } into a structure like this: [ {0:{A:a}}, {1:{B:b}}, {2:{C:c}}, ] Using the spread operator l...
Archaeornis asked 24/7, 2017 at 16:0

5

Solved

I have a problem with code I am supposed to work with. I found a syntax I am not familiar with and I have trouble googling the documentation: export const Something = class Something { constructo...
Adolfoadolph asked 26/1, 2018 at 15:16

7

Solved

Consider the following sample code var x = ["a", "b", "c"]; var z = ["p", "q"]; var d = [...x, ...z]; var e = x.concat(z); Here, the value of d ...
Stanzel asked 1/1, 2016 at 20:48

4

Solved

So I have an array, ex. const arr = [1, 2, 3, 4];. I'd like to use the spread syntax ... to remove the first element. ie. [1, 2, 3, 4] ==> [2, 3, 4] Can this be done with the spread syntax? Edi...
Eidolon asked 25/8, 2018 at 22:35

8

Solved

I'm replacing an item in a react state array by using the ... spread syntax. This works: let newImages = [...this.state.images] newImages[4] = updatedImage this.setState({images:newImages}) ...
Amendment asked 14/8, 2017 at 11:43

3

Solved

Why does spreading undefined in an object return an empty object? {...undefined} // equals {}: console.log({...undefined}) And Why does spreading undefined in an array give you an error...
Forenamed asked 7/11, 2017 at 10:9

3

Solved

Given the following example: // option 1 items.reduce((values, item) => ({ ...values, [item.id]: item.name }), {}) // option 2 items.reduce((values, item) => { values[item.id] = item.na...
Conic asked 30/11, 2019 at 23:36

4

Solved

Basically here's what I'm trying to accomplish. class Person { constructor (obj) { this.first = '' this.last = '' this.age = '' if (obj) { Object.assign(this, ...obj) } } } ...
Perspiratory asked 18/9, 2017 at 6:55

1

Solved

The following gives error TS2556, how do I fix it? class Test { constructor(x: number) {} } class Test2 extends Test { constructor(...args) { super(...args); // TS2556 } } Or if you are using...
Payola asked 14/9, 2021 at 19:33

6

Solved

I have been struggling with a really annoying behaviour of Visual Studio Code recently. Whenever I try to use the JavaScript spread syntax VSCode automatically autocompletes the next piece of code ...

2

Solved

I tried to write ternary operator with spread syntax and copy two objects. Is it possible to use ternary operator with spread syntax inside with literal objects? My code works okay, I just want to ...
Aerial asked 19/7, 2017 at 8:13

7

Solved

I am using following code to get unique numbers: let uniques = [ ...new Set([1, 2, 3, 1, 1]) ]; // [1, 2, 3] However, typescript report following error: Type 'Set' is not an array type. I am not...
Ruiz asked 1/11, 2015 at 16:38

5

Solved

In my flutter app, I have widgets like below: Container( decoration: BoxDecoration( border: Border.all( color: Colors.red, width: 2, style: BorderStyle.solid, ), ), child: Text('Container ...
Krisha asked 7/3, 2019 at 10:34

© 2022 - 2024 — McMap. All rights reserved.