【问题标题】:Reading the javascript object读取 javascript 对象
【发布时间】:2021-11-07 10:28:52
【问题描述】:

我正在尝试为自动投注 (bustabit.com) 编写脚本

他们在github 上有一本关于此的手册

我想读取 engine.history 中的“bust”对象来编写 if 语句

但我不知道 javascript 对象是如何工作的(我没有任何编程经验)

我试过了,但它不起作用

if (engine.history(game.bust)=1.37){log("bust is 1.37")};

有人可以帮忙吗?

【问题讨论】:

  • 那么问题出在哪里?
  • = 符号应该是 == 符号。是的,我知道当你错过这一点时的感觉,尤其是当程序很大时..if (engine.history(game.bust)==1.37){log("bust is 1.37")};
  • 或者试试engine.history.toArray().filter(game => game.bust === 1.37)。只是猜测。

标签: javascript json object


【解决方案1】:

等号用于赋值。

您应该使用 == 进行相等性检查 read this

if (engine.history(game.bust)==1.37){log("bust is 1.37")};

然后

history(game.bust) 意味着历史是一个函数,它接受一个参数,该参数是游戏对象内的属性 bust 的值

Reading what are you sharinghistory 里面有一个方法,它将把历史转换成一个数组。

engine.history.toArray()

之后,您可以使用数组方法来查找您要查找的历史记录项,例如

const engineHistory = engine.history.toArray()
const element = engineHistory.find(historyItem => historyItem.bust == 1.37)

【讨论】:

  • 如果我想为此添加一个 if 语句: const engineHistory = engine.history.toArray(); if(const element = engineHistory.find(historyItem => historyItem.bust == 1.14)) { notify(它的工作); };像这样?
  • @anoobprogrammer 它不会这样工作,你可以这样做:if(element) console.log('its working')因为数组找到元素的结果的真实性,read here
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-12
  • 1970-01-01
  • 2021-01-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多