gpt4 book ai didi

javascript - 如何减去两个数组的元素并将结果存储为javascript中的正数组?

转载 作者:行者123 更新时间:2023-11-30 07:02:06 25 4
gpt4 key购买 nike

假设我有 2 个数组,

A=[1,2,3,4,5,6]
B=[9,8,7,5,8,3]

当我减去数组的元素时,

C=[-8,-6,-4,-1,-3,3]

如何得到减法的结果

C=[8,6,4,1,3,3]

最佳答案

您可以使用 javascript 函数 Math.abs()

C.map(Math.abs);

关于javascript - 如何减去两个数组的元素并将结果存储为javascript中的正数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36161457/

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