【问题标题】:How to creat a function to return an array with 21 waypoints separated如何创建一个函数来返回一个分隔 21 个航点的数组
【发布时间】:2023-03-15 19:32:01
【问题描述】:
我想创建一个包含 21 个航点的 3 个位置的数组..~
为此,我需要这样的功能:
我的默认数组:waypt2 = [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
【解决方案1】:
我不确定你想在这里做什么。据我了解,也许您可以对数组内容尝试这样的操作:
Array.from(
{ length: 21 },
(_, index) => ({
stopover: true,
location: object[index] // ...
})
)
【解决方案2】:
以下代码生成以随机整数为位置的航路点,
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);