ES6 One Liners to Show Off

Follow us on LinkedIn for our latest data and tips!

, ,

ES6 One Liners to Show Off

This is a guest post by Hemanth H.M and was originally published on

Here is a collection of ES6 one liners to show off!

NodeList to Array:

var headings = [ ... document.querySelectorAll('h1') ];Unique Arrays:
[ Set(array) ] 


var {foo, bar} = {foo: "lorem", bar: "ipsum"};
// foo => lorem and bar => ipsum

Swap like a snake:

[a,b] = [b,a]

Max in array?:


List comprehension:

[ for (value of ["Harriet", "178"]) value ].join(" was ");
// Would give us "Harriet was 178"
// BTW it was Charles Darwin's tortoise.


[{id: 1}, {id: 2}].map(x =>
// [1,2]


let Object.isz = (x, y) => x === y ||, y);
//^ Credits to Mark S. Miller.

Is it a hidden file?:

isHidden = (file) => /^\.|~$/.test(file);
isHidden(".DS_STORE") // true

Repeat with me:

(0/0+"").repeat("7")+ " BatMan!"
// "NaNNaNNaNNaNNaNNaNNaN BatMan!"

If you are using some, please do let me know!

Hope it blew your mind! ;)