ES6入门之set和map
ES6中Map与对象、数组,JSON之间的相互转换
let 声明的变量仅在块级作用域内有效
function f1() {
let n = 5;
if (true) {
console.log("里面" + n); // 5
}
console.log(n); // 5
}
箭头函数
let sum = (num1, num2) => {
return num1 + num2;
}
合并数组
let arr1 = ['a', 'b', 'c', 'd'];
let arr2 = ['2', 'b', 'c', 'd'];
let dd = [...arr1, ...arr2];
合并对象
let target = {};
let source1 = {b: 2};
let source2 = {c: 3};
Object.assign(target, source1, source2);
console.log(target);
遍历数组
let myArray = ["I", "LOVE", "CHINA"];
myArray.forEach(function(value, index) {
console.log(value);
console.log(index);
});
myArray.map(function(item, index) {
console.log(item);
console.log(index);
});