var j = [...new Set([1, 2, 3, 3])] // [1, 2, 3]
...
and the data type Set
.false
? For example, these are values such as 0
, undefined
, null
, false
. Perhaps you did not know that in order to do this, you can do this: myArray .map(item => { // ... }) // .filter(Boolean);
Boolean
method to the arrays .filter()
.{}
. But such an object will be assigned a prototype ( __proto__
), it will have a method hasOwnProperty()
and other methods of objects. In order to create a truly empty object , which can, for example, be used as a “dictionary”, you can do this: let dict = Object.create(null); // dict.__proto__ === "undefined" // ,
const person = { name: 'David Walsh', gender: 'Male' }; const tools = { computer: 'Mac', editor: 'Atom' }; const attributes = { handsomeness: 'Extreme', hair: 'Brown', eyes: 'Blue' }; const summary = {...person, ...tools, ...attributes}; /* Object { "computer": "Mac", "editor": "Atom", "eyes": "Blue", "gender": "Male", "hair": "Brown", "handsomeness": "Extreme", "name": "David Walsh", } */
...
greatly simplifies the solution of the problem of merging objects. const isRequired = () => { throw new Error('param is required'); }; const hello = (name = isRequired()) => { console.log(`hello ${name}`) }; // , name hello(); // hello(undefined); // hello(null); hello('David');
const obj = { x: 1 }; // obj.x x const { x } = obj; // obj.x otherName const { x: otherName } = obj;
// , "?post=1234&action=edit" var urlParams = new URLSearchParams(window.location.search); console.log(urlParams.has('post')); // true console.log(urlParams.get('action')); // "edit" console.log(urlParams.getAll('action')); // ["edit"] console.log(urlParams.toString()); // "?post=1234&action=edit" console.log(urlParams.append('active', '1')); // "?post=1234&action=edit&active=1"
URLSearchParams
API URLSearchParams
much easier than solving the same problems using regular expressions.Source: https://habr.com/ru/post/449948/
All Articles