静态网页可从数据库中随机选择数据,而无需将所有内容加载到内存中

时间:2019-12-11 21:16:58

标签: javascript

如何仅使用 客户端JavaScript从GitHub托管的数据库(JSON文件,CSV等)中随机选择一个值?

非常感谢

编辑:示例数据和访问代码

abap channels for event signaling
abap unified connectivity
abdominal exercise apparatus
abdominal fluid management apparatus
ablation catheter
ablation needle guide
ablation stretcher
able stack assembly

(这是原始数据,以换行符分隔。目前,我将其转换为javascript数组,如下所示)

var data = 
[
    "abap channels for event signaling",
    "abap unified connectivity",
    "abdominal exercise apparatus",
    "abdominal fluid management apparatus",
    "ablation catheter",
    "ablation needle guide",
    "ablation stretcher",
    "able stack assembly",
    ...

// Select a random idea
var idea = data[Math.floor(Math.random() * (Object.keys(data).length))];

0 个答案:

没有答案