Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:js_snippets [2020/05/09 08:25] 127.0.0.1 editor externo |
— (actual) | ||
|---|---|---|---|
| Línea 1: | Línea 1: | ||
| - | ====== Javascript Snippets ====== | ||
| - | |||
| - | ===== Objects ===== | ||
| - | |||
| - | ==== Merge two objects ==== | ||
| - | <code> | ||
| - | Object.assign(obj1, obj2); | ||
| - | let newObject = Object.assign({}, obj1, obj2, obj3, etc); | ||
| - | </code> | ||
| - | |||
| - | ===== Arrays ===== | ||
| - | |||
| - | |||
| - | ====== URL parameters ====== | ||
| - | <code> | ||
| - | 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" | ||
| - | </code> | ||
| - | |||
| - | |||
| - | ====== Local Storage ====== | ||
| - | |||
| - | <code> | ||
| - | window.localStorage.setItem('test', 'hola'); | ||
| - | </code> | ||
| - | |||
| - | * setItem(): Add key and value to localStorage | ||
| - | * getItem(): Retrieve a value by the key from localStorage | ||
| - | * removeItem(): Remove an item by key from localStorage | ||
| - | * clear(): Clear all localStorage | ||
| - | * key(): Passed a number to retrieve nth key of a localStorage | ||
| - | |||