"Destructuring allows you to bind a set of variables to a corresponding set of values anywhere that you can normally bind a value to a single variable" ("Common Lisp the Language").
Questions tagged [destructuring]
1338 questions
-2
votes
3 answers
Compelling ECMAScript 6 Destructuring use cases
Why was destructuring introduced to ECMAScript 6?

Sam Leach
- 12,746
- 9
- 45
- 73
-3
votes
3 answers
How to split object key and convert it into array of object?
i'm facing issue to convert object into array of object. i'm having object like,
const employeeDetails = {
"admin-name": "deepak",
"admin-age": "29",
"tester-name": "raju",
"tester-age": "26",
};
i'm expecting format like,
const…

Kumar
- 1
- 1
-3
votes
2 answers
search for value in json and return the main key
i have a json with structure like this
{
"india": {
"north_states": ["TN", "AP", "MP", "AB"],
"south_states": ["PB", "UP", "RJ", "HR"]
},
"us": {
"north_states": ["AC", "AD", "AE", "AF"],
"south_states": ["BA", "BB", "BC",…

Nnandan15
- 7
- 1
- 5
-3
votes
1 answer
t.isRestProperty is not a function at DestructuringTransformer.pushObjectPattern
The code I am trying to execute is as below.
const obj = {place: 'kar', number: 45};
const {place, number} = obj;
console.log(place);
I get the following error while using ES6 object destructuring.
t.isRestProperty is not a function
at…

Vijay N Rao
- 21
- 1
- 7
-3
votes
1 answer
Array destructuring with complex nested object
I have the following line with destructuring syntax;
const [
{data: dataResponse},
{data: stateDistrictWiseResponse},
{data: statesDailyResponse},
{data: stateTestResponse},
{data: sourcesResponse},
{data: zonesResponse},
] =…

copenndthagen
- 49,230
- 102
- 290
- 442
-3
votes
1 answer
Why console.log(myObj) prints an error in JS.Bin?
Here is a simple exercise that i don't finish to understund:
const myObj = {
name: 'Max',
age: 28
}
const {name} = myObj;
console.log(name); // prints 'Max'
console.log(age); // prints undefined
…

Carlos Pérez
- 167
- 1
- 10
-3
votes
2 answers
How can I do destructuring assignment in Reactjs?
I have the following function.
returnStateElement = (...elements) => {
const copy = Object.assign({}, this.state);
return elements.reduce((obj, key) => ({ ...obj, [key]: copy[key] }), {});
};
Working:
f = () => {
const dataSender =…

Paul
- 3,644
- 9
- 47
- 113
-3
votes
3 answers
JS destructuring into other variable
I am not sure this is even possible. I don't know how to do this.
So I have these object:
const testObject1 = {first: 25, second: 2};
let testObject2 = {property1: 0, property2: 29};
and I want to put the "first" property of testObject1 in…

Laurent Dhont
- 1,012
- 1
- 9
- 22
-3
votes
2 answers
Object destructing using ES6
I have this nested object that contains also an array.
result:{
"a": [{ "b": { "c": 1,
"d": 2,
"e": 3
},
"f": 0
}]
}
How can I destructure this object using ES6 if I need the value of d?

ade
- 9
- 1
- 4
-3
votes
2 answers
how to solve this in javascript?
> Locate the `displayBirthdate` function you initially defined, which took no parameter. Modify it to use object de-structuring to get just the 'dob' property of the parameter object it will receive
here's the code
```javascript
const…

Devjoseph
- 61
- 1
- 4
-3
votes
1 answer
Destructure a function parameter in Javascript
I have function called displayUserDetail with a an api object passed as a parameter called userData from this API — https://randomuser.me/api.
Here's an example API response (trimmed down):
{
"results": [
{
"gender": "male",
…

Yemi Esuga
- 1
- 3
-3
votes
1 answer
is used destructuring in Promise.resolve with value thenable Object?
The following code use Destructuring:
var obj = {
fun1:function() { console.log('Working') }
};
obj = { fun1:function(){ console.log("Replaced Working")} }
obj.fun1();
//output:
//Replaced Working
Does the following Promise do the same?
var pr…

Ehsan
- 12,655
- 3
- 25
- 44
-3
votes
1 answer
Destructoring from function arguments
I pass a single argument to a react functional component. What I need, is to destructore classes from props, but remain props intact, so I can refer to a props like props.title inside the component, but use classes without writing props.classes,…

exoslav
- 2,094
- 3
- 21
- 26
-3
votes
2 answers
Is [number, number] a tuple type?
In the below code,
function f([first, second]: [number, number]){
console.log(first);
console.log(second);
}
var input:number[] = [1,2];
f(input);
number[] type variable(input) is passed to f.
Why compiler errors out? Argument of type…

overexchange
- 15,768
- 30
- 152
- 347
-4
votes
1 answer
I would like separate Object values based on Object keys
Need to merge other country cities data into single object. my inputs are below
result = {
"Bangalore": [
{
"Type": "Sale",
"Date": "2021-07-10",
},
{
"Type": "Product",
"Date": "2021-07-03",
}
],
…

Jay
- 187
- 2
- 13