我有一个键和值对格式,我想过滤数组中的所有值到一个数组中
const holiday_expenses = {
food: [{name: "abc", place: "xyz"}],
travel: [{name: "abcd", place: "xyz1"}],
accommodation: [{name: "xysz", place: "xyz2"}]
}
字符串
预期结果:
result : [{name: "abc", place: "xyz"}, {name: "abcd", place: "xyz1"}, {name: "xysz", place: "xyz2"}]
型
2条答案
按热度按时间w1jd8yoj1#
只需要得到所有的object's values和flatten:
字符串
完整片段:
型
gk7wooem2#
字符串
检查“lodash”,我相信它可以让你的生活更好。https://lodash.com/docs/有很多帮助函数来操作数组和对象。