![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
javascript
爱撸铁的Coder
这个作者很懒,什么都没留下…
展开
-
js对象中key值加引号和不加引号有什么不一样?
js对象中key值加引号和不加引号的区别一般情况下,对象key值加引号和不加引号的都是一样的let obj = { id: 1, name: "vici"};console.log(obj['id']);//1console.log(obj.id);//1但是如果对象里的属性名是以数字开头的,就要将属性名用引号引起来,并且只能通过中括号的方式取,不能用 . 的方式取。let obj = { id: 1, '111name': "vici" };con原创 2021-01-23 10:30:40 · 3519 阅读 · 1 评论 -
JavaScript reduce()函数用法
1.统计数组元素出现的次数let arr = ['Alice', 'Bruce', 'David', 'William', 'Bruce', 'Alice'];arr.reduce((pre, cur) => { if (cur in pre) { pre[cur]++; } else { pre[cur] = 1; } return pre; }, {})2.数组去重let arr = [1, 2, 2, 3, 4, 4原创 2021-01-19 09:50:33 · 188 阅读 · 0 评论