我有两个数组,一个带有x坐标,一个带有y坐标。我需要创建一个将坐标分组的新数组数组。
yCord = [30, 29, 31, 32];
xCord = [0, 1, 2 ,3];
这就是我所拥有的。
var cordPairs = {};
xCord.forEach((key, i) => cordPairs[key] = yCord[i]);
但这将对象中的值配对,我现在需要一个数组。
{0: 30, 1: 29, 2: 31, 3: 32}
所需结果:
cordPairs = [[0, 30], [1, 29], [2, 31], [3, 32]]
您需要array
格式的数据,这样才能正常工作:
const yCord = [30, 29, 31, 32];
const xCord = [0, 1, 2 ,3];
const coords = xCord.map((el, index)=> [el, yCord[index]]);
console.log(coords);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句