判断数据类型
1 | // 工具函数 |
数组去重方法
键值对原理
1 | let x = [1, 3, 4, 1, 4, 6, 9]; |
ES6 set
1 | let arr = [1, 3, 4, 1, 4, 6, 9]; |
判断是否为空
1 | function isEmpty(value){ |
比较属性
不同的引用类型含有相同的属性
If they’re distinct objects, even if they contain identical properties, the comparison will result in false
.
1 | var arr1 = ['Hi!']; |
If we have two distinct objects and want to see if their properties are the same, the easiest way to do so is to turn them both into strings and then compare the strings. When the equality operators are comparing primitives, they simply check if the values are the same.
1 | var arr1str = JSON.stringify(arr1); |
Another option would be to recursively loop through the objects and make sure each of the properties are the same.