javascript ES6,7,8有用的例子#javascript
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript ES6,7,8有用的例子#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 = {
}
}
以上是关于javascript ES6,7,8有用的例子#javascript的主要内容,如果未能解决你的问题,请参考以下文章