Show Menu
Cheatography

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) { consol­e.l­og(­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.sp­lic­e(s­tart, delete­Count [, item1 [, item2 ...]])

Chomp string

string = string.slice(0, -1);

Strings: substr VS substring

string.su­bst­r(s­tart, length)
string.su­bst­rin­g(s­tart, stop)
 

Clonin­g/A­ssi­gnment

Object.as­sig­n(obj1, obj2);
to clone:
let clone = Object.as­sig­n({}, obj1); // Though not sure if swallow or deep copy

"­Fal­sy" values in JS

Undefined
null
false
+0
,
-0
, and
NaN
"­"
 

Array aggreg­ation

array1 = array1.concat(array2);

Array includes element

array1.includes('xyz')

Case insens­itive compar­isson

(a, b) => a.toLowerCase().localeCompare(b.toLowerCase())

Logging companions

http:/­/1l­ine­art.ku­lao­ne.c­om/#/
http:/­/ba­da5­5.io/

For something like:
consol­e.l­og(­'%cd[ o_0 ]b %s', 'color: #fa5732;', 'DATA');

(always) Thanks to MDN

 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          AngularJS Cheat Sheet
          JavaScript Cheat Sheet

          More Cheat Sheets by dimitrios

          CoffeeScript Cheat Sheet
          vim.spf13 Cheat Sheet
          The 30 CSS Selectors You Must Memorize Cheat Sheet