我想创建一个包含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;
}
我不确定你在这里想要做什么。根据我的理解,也许你可以尝试这样的数组内容:
Array.from(
{ length: 21 },
(_, index) => ({
stopover: true,
location: object[index] // ...
})
)
下面的代码生成以随机整数作为位置的方式点,
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);