javascript
Javascript ES6 Destructuring
const Person = {
name: "John Snow",
age: 29,
sex: "male",
materialStatus: "single",
address: {
country: "Westeros",
state: "The Crownlands",
city: "Kings Landing",
pinCode: "500014",
},
};
const { address : { state, pinCode }, name } = Person;
console.log(name, state, pinCode) // John Snow The Crownlands 500014
console.log(city) // ReferenceErro
//Extract especif information from objects array
let array = [ {"name":"Joe", "age":17, "sex":"M"},{"name":"Bob", "age":17, "sex":"M"},{"name":"Carl", "age": 35, "sex":"M"}];
let especifArrayAtributes = array.map(x => ({firstname: x.name, age : x.age}));
console.log(especifArrayAtributes); //"[{"firstname":"Joe","age":17},{"firstname":"Bob","age":17},{"firstname":"Carl","age":35}]"
Was this helpful?
Similar Posts
- Assign items of arrays to multiple variable when creating it (Array Destructuring) Javascript(ES6)
- Swapping two values using Destructuring in Javascript
- Javascript ES6 Array Filter
- Javascript ES6 Spread Operator
- Javascript ES6 Rest Parameters
- Javascript ES6 Template strings
- JavaScript ES6 filtering object with multiple params