link-in - רשומות קוד

חפש את הקוד שלך >

Destructuring in JavaScript

היכולת לבצע השמה של משתנים במערך\ אובייקט , בצורה מקוצרת 

var arr = ['Hermione', 'Ron', 'Harry', 'Dumbledore'];

// Destructuring the array
var [best, worst, ...others] = arr;
var obj = {
	name: 'Hermione',
	house: 'Gryffindor',
	points: 9640
};

// Destructuring an object
var {name, house, ...otherDetails} = obj;