Skip to content

Instantly share code, notes, and snippets.

@zoonderkins
Created January 30, 2018 08:54
Show Gist options
  • Save zoonderkins/1f7553c1a522e9ac12614686c0beda1f to your computer and use it in GitHub Desktop.
Save zoonderkins/1f7553c1a522e9ac12614686c0beda1f to your computer and use it in GitHub Desktop.
ES6,7,8 useful example #javascript
* Object.entries() method returns an array of a given object’s own enumerable property [key, value] pairs.
var fruits = {
apple: 10,
orange: 20,
grapes: 30,
pineapple: 40
}
for (var [key, val] of Object.entries(fruits)) {
console.log(key, val);
}
> Output:
>apple 10
>orange 20
>grapes 30
>pineapple 40
* Object.values () : You are familiar with Object.keys(). This is exactly opposite of Object.keys().
var fruits = {
apple: 10,
orange: 20,
grapes: 30,
pineapple: 40
}
var totalVegetables = Object.values(fruits).reduce((a, b) => a + b);
console.log(totalVegetables);
>Output : 100
3**3 = 27
2**2**2 = 16
class Animal {
constructor() {
this.name = "Lion"
}
age = 0;
}
That will be complied to:
class Animal {
constructor() {
this.age = 0;
this.name = "Lion";
}
}
Especially react developers can relate easily state! and initialProps!:
class Animal {
constructor() {
this.name = "Lion"
}
age = 0;
state = {
}
initialProps = {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment