Code Fragmente Javascript
// Iterating over objects
const unknownObject = { /* ... */ }
for (const [ key, value ] of Object.entries(unknownObject)) {
// unbekantes Obejkt richtig coden
}
//Omitting unneeded values by just using some commas:
const [,, month] = '2018-07-31'.match(/^[0-9]{4}.([0-9]{2}).[0-9]{2}$/)
// You can also clone an array with destructuring:
const arr = ["one", "two"];
const clone = [...arr];
function myFunction(text = "", line = 0, truncate = 100) {
// With default values, we can avoid a bunch of:
text = text || "";
line = line || 0;
truncate = truncate || 100;
}
const { x: otherName } = obj;
const User = {
name: 'John Doe',
age: 30
};
const { name: fullName, age: userAge } = User;