如何创建一个函数来返回一个分离了21个路点的数组

问题描述 投票:0回答:2

我想创建一个包含3个位置包含21个航点的数组..~为此我需要一个这样的函数:我的默认数组:way pt2 = [Array(22),Array(22),Array(17)]

function work_waypoints(waypt2){
    waypts.push({
      location: waypt2[i][g].latlgn,
      stopover: true // obrigatório paragem
    });
    return waypts;
  }
javascript directions
2个回答
0
投票

我不确定你在这里想要做什么。根据我的理解,也许你可以尝试这样的数组内容:

Array.from(
  { length: 21 },
  (_, index) => ({
    stopover: true,
    location: object[index] // ...
  })
)

0
投票

下面的代码生成以随机整数作为位置的方式点,

function generateWaypoints(){
  console.log(Array.from({length: 3}, () => Math.floor(Math.random() * 150)));
}

Function.prototype.sequence = function(from, to) {
    for (var i = from; i <= to; i++) this.call(null, i);
};

generateWaypoints.sequence(0, 21);
© www.soinside.com 2019 - 2024. All rights reserved.