博客
关于我
再返回结果的数组对象里面添加一个新的字段
阅读量:680 次
发布时间:2019-03-17

本文共 400 字,大约阅读时间需要 1 分钟。

var arry = [{a:11,b:22,c:33,d:44},{a:11,b:0,c:0,d:44},{a:11,b:22,c:99,d:99}];var arry2 = [];arry.map((item, index) => {    arry2.push(Object.assign({}, item, {mess1: item.c, mess2: item.d}));});console.log(arry2);

通过上述代码,可以看到数组字段的值会被合并到新的对象中。通过map函数将原数组中的对象逐一处理,生成包含附加字段mess1和mess2的新对象列表。最终将处理结果输出。该方法通过单纯的赋值操作实现字段的扩展,符合数据操作的业务需求。

原文链接:https://blog.csdn.net/qq_24147051/article/details/80541112

你可能感兴趣的文章
php echo 输出 锘?... 乱码问题
查看>>
PHP empty、isset、isnull的区别
查看>>
ReferenceQueue的使用
查看>>
PHP FastCGI进程管理器PHP-FPM的架构
查看>>
referenceQueue用法
查看>>
php flush()刷新不能输出缓冲的原因分析
查看>>
Referenced classpath provider does not exist: org.maven.ide.eclipse.launchconfig
查看>>
Refactoring-Imporving the Design of Exsiting Code — 代码的坏味道
查看>>
PHP imap 远程命令执行漏洞复现(CVE-2018-19518)
查看>>
php include和require
查看>>
ref 和out 区别
查看>>
php JS 导出表格特殊处理
查看>>
php json dom解析
查看>>
ReentrantReadWriteLock读写锁解析
查看>>
php laravel实现依赖注入原理(反射机制)
查看>>
php laravel请求处理管道(装饰者模式)
查看>>
ReentrantReadWriteLock读写锁底层实现、StampLock详解
查看>>
PHP mongoDB 操作
查看>>
ReentrantLock读写锁
查看>>
ReentrantLock的公平锁与非公平锁
查看>>