Cheatography
https://cheatography.com
My Javascript notes, stuff that I use often in the curent project I'm working on
For loop
let iterable = [1, 2, 3];
for(let value of iterable) { console.log(value); } |
Slice VS Splice
slice |
shallow |
splice |
changes |
The slice() method retrurns a shallow copy of a portion of an array into a new array object:
arr.slice([begin[, end]])
The splice method changes the content of an array by removing existing elements and/or adding new elements.
arr.splice(start, deleteCount [, item1 [, item2 ...]])
Chomp string
string = string.slice(0, -1);
|
Strings: substr VS substring
string.substr(start, length) |
string.substring(start, stop) |
|
|
Cloning/Assignment
Object.assign(obj1, obj2);
to clone:
let clone = Object.assign({}, obj1); // Though not sure if swallow or deep copy |
|
|
Array aggregation
array1 = array1.concat(array2);
|
Case insensitive comparisson
(a, b) => a.toLowerCase().localeCompare(b.toLowerCase())
|
|
Created By
Metadata
Favourited By
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets
More Cheat Sheets by dimitrios