La estructuración es una nueva forma de asignar valores sobretodo a arrays y objects. Es un patrón muy utilizado cuando se está trabajando en componentes de React.js.
La variable que se trata de crear tiene que ser igual a la propiedad que se quiere dejar en una sóla variable.
Ejm
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Destructuración</title>
</head>
<body>
<h1>Destructuración</h1>
<script>
// DESTRUCTURACION DE ARRAY
const numeros = [1, 2, 3];
// NECESITO ESTOS NÚMEROS GUARDARLOS EN VARIABLES DIFERENTES SIN DESTRUCTURACIÓN
let uno = numeros[0],
dos = numeros[1],
tres = numeros[2];
console.log(uno, dos, tres);
// NECESITO ESTOS NÚMEROS GUARDARLOS EN VARIABLES DIFERENTES CON DESTRUCTURACIÓN
const [one, two, three] = numeros;
console.log(one, two, three);
// DESTRUCTURACIÓN DE UN OBJETO
let persona = {
nombre: "Francisco",
apellido: "Paredes",
edad: 15,
};
const { nombre, apellido, edad } = persona;
console.log(nombre, apellido, edad);
</script>
</body>
</html>