当前位置:网站首页>Use lodash to merge the values of the same fields in an array object
Use lodash to merge the values of the same fields in an array object
2022-06-13 03:43:00 【_ Virgo programmer's daily life】
If it's in vue Using this method :
Specific in vue How to use loadash See the last article :
<script>
export default {
created(){
let fruitSamples = [
{
id: 1, type: 'apples', samples: [{
id: 1, name: 1 }] },
{
id: 2, type: 'bananas', samples: [{
id: 2, name: 2 }] },
{
id: 3, type: 'pears', samples: [{
id: 3, name: 3 }] },
{
id: 1, type: 'apples', samples: [{
id: 11, name: 11 }] },
]
this.mergeArrObj(fruitSamples,'type');
},
methods:{
// fruitSamples Array objects to be merged ,type Which attribute should be merged according to
mergeArrObj(fruitSamples,type){
function customizer(objValue, srcValue) {
if (_.isArray(objValue)) {
return objValue.concat(srcValue)
}
}
// Pass the parameters to be processed
let test = _(fruitSamples)
.flatten()
.groupBy(type)
.map(
_.spread((...values) => {
console.log("value How much is the ")
console.log(...values);
return _.mergeWith(...values, customizer)
}),
)
.value()
console.log("test How much? ")
console.log(test)
// -> give the result as follows :
[
{
id: 1, type: 'apples', samples: [1, 2, 3, 5, 2, 9, 11, 2, 33] },
{
id: 2, type: 'bananas', samples: [1, 2, 7, 1, 7, 7, 17, 2, 67] },
{
id: 3, type: 'pears', samples: [1, 2, 3, 12, 21, 32, 91, 22, 34] }
]
}
}
}
</script>
边栏推荐
- Lambda终结操作count
- 测试写入mysql数据300W条,每次1.6-2W之间就断掉然后出现以下问题:
- Economic panel topic 1: panel data of all districts and counties in China - more than 70 indicators such as population, pollution and agriculture (2000-2019)
- Doris' table creation and data division
- Solve the error in CONDA installation PyMOL
- China Civil Aviation Statistical Yearbook (1996-2020)
- Oracle database management
- LVS四层负载均衡集群(3)集群功能分类 - HPC
- Spark Optimization -- differences and policy selection of RDD cache (cache, persist, checkpoint)
- Cross border M & a database: SDC cross border database, Thomson database, A-share listed company M & a database and other multi index data (4w+)
猜你喜欢
![[azure data platform] ETL tool (9) -- ADF performance optimization case sharing (1)](/img/5d/1fc04b4384af07b953c99ec37383b3.jpg)
[azure data platform] ETL tool (9) -- ADF performance optimization case sharing (1)

LVS四层负载均衡集群(5)LVS概述

【测试开发】测试管理工具禅道的安装

The latest summary of key topics of journal C in 2022 - topic scope, contribution method and journal introduction

Simulink代码生成: 简单状态机及其代码

Feign based remote service invocation

Prefecture level city - air flow coefficient data - updated to 2019 (including 10m wind speed, boundary height, etc.)

Tencent cloud instant messaging IM

User and permission configuration in SQL Server database to ensure database security

Workflow of driver of spark kernel (stage division, task division, task scheduling)
随机推荐
What to bring to 2022
To resolve project conflicts, first-class project managers do so
[azure data platform] ETL tool (2) -- azure data factory "copy data" tool (cloud copy)
P1048 [noip2005 popularization group] Drug collection
【测试开发】进阶篇——各种测试技术分类
MySQL learning summary Xi: detailed explanation of the use of stored procedures and stored functions
[azure data platform] ETL tool (7) - detailed explanation of ADF copy data
19 MySQL database optimization methods
【测试开发】测试管理工具禅道的安装
Detailed explanation of MySQL storage process
基于华为云物联网设计的浇花神器(STM32+ESP8266)
【youcans 的 OpenCV 例程200篇】201. 图像的颜色空间转换
【測試開發】自動化測試selenium(三)——unittest框架解析
V-bind and v-on
Part II. S3. intuitionistic fuzzy multi-attribute decision-making method when attribute weight is intuitionistic fuzzy number
【测试开发】自动化测试selenium(二)——webdriver常用的API
Simulink代码生成: 查表模块及其代码
[test development] blog system - LoadRunner performance test (publish blog function benchmark test)
Watering artifact based on Huawei cloud Internet of things (stm32+esp8266)
LVS四層負載均衡集群(5)LVS概述