Skip to content

Instantly share code, notes, and snippets.

@netsi1964
Created July 18, 2017 08:15
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 netsi1964/18c1f984f7431ce8da4e532fd9a39705 to your computer and use it in GitHub Desktop.
Save netsi1964/18c1f984f7431ce8da4e532fd9a39705 to your computer and use it in GitHub Desktop.
ES8 aka ES2017 aka EcmaScript 8 aka EcmaScript 2017 released
// padStart and padEnd
var now = new Date();
console.log(`${now.getHours().toString().padStart(2,"0")}:${now.getMinutes().toString().padStart(2,"0")}`)
/* Output:
09:41 (or something simular)
*/
// Object.values
var objectTypes = {}
Object.values(window).map(obj => {
const type = typeof obj;
if (typeof objectTypes[type] != 'undefined') {
objectTypes[type] = objectTypes[type]+1;
} else {
objectTypes[type]=0;
}
})
var output = `The values of the keys found in the window object of the page "${document.location}" has:`
Object.keys(objectTypes).map(type => {
output+=`\n"${type}" found ${objectTypes[type]} times`
})
console.log(output)
/* OUTPUT:
The values of the keys found in the window object of the page "https://gist.github.com/" has:
"function" found 58 times
"object" found 142 times
"undefined" found 1 times
"number" found 13 times
"boolean" found 1 times
"string" found 5 times
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment