Questions tagged [object-destructuring]

Use this tag for JavaScripts object destructuring syntax.

JavaScript object destructuring allows one to replace code like:

const object = {foo: 'bar', baz: 'bing'};
const foo = object.foo;
const baz = object.baz;

With this destructuring assignment syntax:

const object = {foo: 'bar', baz: 'bing'};
const {foo, baz} = object;
155 questions
0
votes
2 answers

...rest not working in Edge, React project

handleSaveDefault = () => { let { Default, ...rest } = this.state.views; this.handleViewMenuClose(); let setState = () => { return this.setState({ views: { Default: [...this.state.selectedFields], ...rest }, }); …
0
votes
2 answers

Destructure JS object with similar children

I have the following setup, but keep getting the error: Argument name clash. How can I destructure this and still maintain the value? const Message = ({message: { user, text }, nickname}, {quest: { user, text }, nickname} ) =>{
Papi
  • 73
  • 6
0
votes
2 answers

How is this javascript object destructuring working?

I am trying to understand this React redux example on : https://codesandbox.io/s/f2ded In reducer.js, the initial state is : const initialState = { taskName: "", tasks: [] }; In App.js, we have : const mapStateToProps = state => { return { …
Ano
  • 11
  • 1
  • 1
  • 6
0
votes
1 answer

Nested object destructuring with redux and react

I'm following a tutorial in React Redux. I have created a store variable with Redux store which has two sub variables. One is expenses which is an array of objects and another is filters which is an object itself. const store = createStore( …
ahrooran
  • 931
  • 1
  • 10
  • 25
0
votes
1 answer

How to destructure Cloud Function parameters?

I have been trying for a while now to do something that should be very simple but I keep running into problems. What is the correct way to destructure the snapshot parameter in a firestore cloud function trigger and assign types? Here's how the…
0
votes
1 answer

User.findOne is looping over in object destructuring string key

I am going with an online course, there's a part where the instructor says he is trying to find/ validate a user using User.findOne and passes some conditions to find the requested user. To pass the value, he uses object destructuring. Heres the…
user12200634
0
votes
1 answer

What is the right way to define es6 function type

while learning in react 16.8 with typescript code base, I came through many diffrent type definition pattern is been followed. so for the sake of consistency, which is the right way (recommended or valid) to set a type definition of a es6 arrow…
xkeshav
  • 53,360
  • 44
  • 177
  • 245
0
votes
1 answer

Does object destructing uses more memory if i use it in most of the components?

Let's say i have this component, export default function Xyz(props) { ... } If i use object destructing, export default function Xyz({x, y, z}) { ... } I want know that if i use the destructing method for every method for every function…
0
votes
1 answer

How can I merge the destructed object keys again?

as you can see I have to destruct the getters which I need to sum them and get how much income they have. here is an example code this is a getter in Vuex store, but this is not important it's rather related to javascript and not vue itself. …
Kepi
  • 116
  • 9
0
votes
2 answers

ESLint | Assignment to property of function parameter 'payload'

I have the following utility method: it removes all the empty keys of a payload object. Here is the code: const removeEmptyKeysUtil = (payload: any): any => { Object.keys(payload).map( (key): any => { if (payload && payload[key] === '')…
user10104341
0
votes
2 answers

Destructuring a TypeScript Object

I'm trying to desctructure an object into another object, I mean taking sub-set of properties from Object A to Object B. I'm doing it like this: const User = new UserImpl(); User.email = user.email; User.name = user.name; …
basel.ai
  • 157
  • 2
  • 15
0
votes
1 answer

Deep destructuring with saving values

How to destruct and save nested values? const obj = { foo: { bar: 'Hi!' } }; const { foo: { bar } } = obj; console.log(bar); // Hi! console.log(foo); // foo is not defined :( How to keep foo value?
user11032667
0
votes
4 answers

How to destructure an array from inside an object in javascript?

I have an object like this: obj = {'id': 1, a: [1, 2, 3]} I want to destructure and get the array a from obj arr = {...obj.a} I get: {0: 1, 1: 2, 2: 3} which is not an array How to get the array itself ?
moctarjallo
  • 1,479
  • 1
  • 16
  • 33
0
votes
0 answers

Guard against undefined in object deconstruction with default values

In Javascript it is possible to deconstruct objects and supply default values to declare variables. Below the name property of school object inside user object would be assigned to the name variable. However this also happens for undefined…
Björn
  • 12,587
  • 12
  • 51
  • 70
0
votes
0 answers

Object destructuring in ES6

I have a function which just return the part of existing object. in this case I am using Object destructuring but for this I need to repeat my code twice, one for retrieving properties and once for creating object like below. function…
Atul
  • 3,013
  • 2
  • 12
  • 15