如何使用提取的数据设置数组的计时器值



我试图从python文档中设置计时器的值,我的问题是,在获取数据后,如何插入每个区域的时间?

fetch('https://python document/')
.then((data) => data.json())
//
.then((data) =>
console.log(data)
//do I have to pass it on from here to the array below?
)
//
.catch(error =>{
console.log('does not work!');
})
};
const allAreas = [
createArea('area-1', whatever we get from the python will set the time here in minutes, ex 60 * 60),
createArea('area-2', and here ex 10* 60),
createArea('area-3', and here ex 20 * 60),
createArea('area-4', and here  ex 30* 60),
createArea('area-5', and here ex 40* 60),
createArea('area-6', and here ex 50 * 60),
createArea('area-7', and here ex 90 * 60),
createArea('area-12', and here ex 120 * 60), 
];

我不确定如何将从获取请求中获得的值传递给数组。

请帮忙。

这在很大程度上取决于获取数据的结构方式。

这也取决于您想要实现的目标,您希望数组中的这些值始终存在吗?

你想在跨页面重新加载或网站的各个页面时保留此功能吗(假设你正在创建某种网站(

做到这一点最简单的方法是这样->

const createArea = function (area, timer) {
console.log(area, timer) // Your logic here...
}
let allAreas = []
fetch('https://dummyjson.com/products/1')
.then(res => res.json())
.then(json => {allAreas.push(createArea('area-5', (json.price * 60)))})

最新更新