欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

map的应用笔记

程序员文章站 2022-07-13 23:45:16
...

map的简单应用

map往数组中添加元素

// 原数组
let list = [
{code:'hospitalA',name:'医院A'},
{code:'hospitalB',name:'医院B'}
]
// 往数组中追加元素
const newList = list.map(it => ({
	...it,
	children: []
}));
// 执行后
list = [
	{code:'hospitalA',name:'医院A',children:[]},
	{code:'hospitalB',name:'医院B'},children:[]
	]


相关标签: nodejs node.js