javascript - From an array of objects, extract value of two properties into an array
问题描述
Consider a JavaScript object array with the following structure:
objArray = [ { foo: 1, bar: 2, anotherfoo:5}, { foo: 3, bar: 4, anotherfoo: 8}];
How can I use map to extract foo and anotherfoo into a new array. Possible duplicate of
解决方案
arr.map(({foo, anotherfoo}) => ({foo, anotherfoo}))
推荐阅读
- graphql - Prisma2 错误:无效的 `prisma.post.create()` 调用:类型 PostUncheckedCreateInput 的 data.tags 中的未知 arg `tags`
- javascript - 如何让你的 webapp 与 chrome 扩展交互?
- zapier - 您可以在 SEMRush 内容审核中创建任务并使用 Zapier 将任务发送到 Trello 吗?
- python - 将属性从一个类传递到另一个类
- angular - Angular 风格
- angular - Angular TypeError:无法读取未定义的属性“匹配”
- bash - zsh 和 bash 子shell 中随机值生成的差异
- mule - Mule 4 中的 Google Sheets 1.1 配置
- python - Python OpenCV图像到视频并非所有图像都以帧显示
- python - 如何提供一些安全访问?