我正在尝试编写一个 JS 算法,其中有两个arrays.
第一个值将具有不同的数值。第二个数组将是常量,例如[5, 3, 6, 8]。
现在我想将第一个数组中的值乘以第二个数组中相应的索引值[3, 7, 2, 5],因此有一个这样的第一个数组:它看起来像这样:5*3、3*7、6*2, 8*5。
根据结果,我想创建一个新数组,在本例中为[15, 21, 12, 40].
我怎样才能达到这个结果?
我正在使用技术堆栈MERN和Redux. 我想知道如何使用moongose. 例如,假设它将是分配给特定用户的订单列表。
我已经在后端完成了一个检索所有记录的查询。它看起来像这样:
const getMyOrders = asyncHandler(async (req, res) => {
const orders = await Order.find({ user: req.user._id })
res.json(orders)
})
Run Code Online (Sandbox Code Playgroud)
在前端,订单列表由以下人员提供redux action:
export const listMyOrders = () => async (dispatch, getState) => {
try {
dispatch({
type: ORDER_LIST_REQUEST,
})
const {
userLogin: { userInfo },
} = getState()
const config = {
headers: {
Authorization: `Bearer ${userInfo.token}`,
},
}
const { data } = await axios.get(`/api/orders/myorders`, config)
dispatch({
type: ORDER_LIST_SUCCESS, …Run Code Online (Sandbox Code Playgroud)