gpt4 book ai didi

javascript - 如何不通过整个响应映射对象

转载 作者:行者123 更新时间:2023-11-30 13:48:21 24 4
gpt4 key购买 nike

我目前有一个表,其中显示了 axios 调用的 3 个不同条目。我正在使用 const details 对象映射该响应,以测试我的响应中的数据。我成功地为所有 3 个响应映射了我的 const details 对象。但我只想显示我的详细信息对象表的 2/3 条目,而不是完整条目 3. 不让我的对象映射到最终条目的最佳方法是什么?

const details = 
{
ActionStatus: "Pending",
RequestedBy: "Jon Snow",
ActionRequested: "Canceled"
},

const getInfo= () => {
return infoApi
.getDirectInfo({
date: selectedDate,
})
.then(response => {
console.log(response)
dispatch({
type: "FETCH_INFO",
payload: {
loading: false,
data: response.map(r=>({...r,...details})),
lastUpdated: new Date().getTime()
}
})}
)

最佳答案

Array.map() 将始终生成与输入数组长度相同的新数组(一对一映射)。如果您想根据某些条件减小数组的大小,可以使用 Array.filter()https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

关于javascript - 如何不通过整个响应映射对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58827476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com