今天在开发过程中想到一个用ES6的filter、findIndex来实现对象数组去重的方法,感觉比较容易理解和使用,直接上代码吧:
1 | const objArr = [{ id: 1, age: 12 }, { id: 2, age: 12 }, { id: 1, age: 15 }] |
去重特点: 取第一个出现的元素
缺失模块。
1、请确保node版本大于6.2
2、在博客根目录(注意不是yilia根目录)执行以下命令:
npm i hexo-generator-json-content --save
3、在根目录_config.yml里添加配置:
jsonContent:
meta: false
pages: false
posts:
title: true
date: true
path: true
text: false
raw: false
content: false
slug: false
updated: false
comments: false
link: false
permalink: false
excerpt: false
categories: false
tags: true