Skip to content

Instantly share code, notes, and snippets.

@hygull
Last active December 30, 2018 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hygull/1bc9f36e29db5848fdbd3de9a2fe5640 to your computer and use it in GitHub Desktop.
Save hygull/1bc9f36e29db5848fdbd3de9a2fe5640 to your computer and use it in GitHub Desktop.
Object, type, check, split, map, number
> Object.prototype.toString.call(a)
'[object Array]'
>
> Object.prototype.toString.call(a).slice(8, -1)
'Array'
>
> Object.prototype.toString.call(a).slice(8, -1);
'Array'
>
> Object.prototype.toString.call(b).slice(8, -1);
'String'
>
> Object.prototype.toString.call(c).slice(8, -1);
'Number'
>
> Object.prototype.toString.call(d).slice(8, -1);
'Number'
>
> Object.prototype.toString.call({}).slice(8, -1);
'Object'
>
> Object.prototype.toString.call(6 < 8).slice(8, -1);
'Boolean'
>
> Object.prototype.toString.call(6 < 8).slice(8, -1).slice(0,-2);
'Boolean'
>
> Object.prototype.toString.call(6 < 8).slice(8, -1);
'Boolean'
>
> o = {p: 1, q: 67, r: 87};
{ p: 1, q: 67, r: 87 }
>
> o2 = {ff: 90, ...o}
{ ff: 90, p: 1, q: 67, r: 87 }
>
> b = [2, 5, 6, 7]
[ 2, 5, 6, 7 ]
>
> c = [45, 78, 90, ...b]
[ 45, 78, 90, 2, 5, 6, 7 ]
>
> c + c
'45,78,90,2,5,6,745,78,90,2,5,6,7'
>
> b + c
'2,5,6,745,78,90,2,5,6,7'
>
> (b + c).split(",");
[ '2', '5', '6', '745', '78', '90', '2', '5', '6', '7' ]
>
> (b + c).split(",").map((s) => Number(s));
[ 2, 5, 6, 745, 78, 90, 2, 5, 6, 7 ]
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment