javascript - 当我添加两件事时,它会显示 [object Object] [object Object]
问题描述
当我运行代码(见要点)时,机会制作了一个 40 字符串长的数字集,然后用于制作另一个数字集。这个数字通常看起来像这样。0.8492767284624279 0.23668391536921263 然后我尝试将两者相加,并在控制台中得到 [object Object][object Object]。
我真的不知道该尝试什么。谷歌没有帮助我
const crypto = require('crypto')
var Chance = require('chance');
var chance = new Chance();
//getting everything I need
var 1 = chance.hash({length: 40})
var 2 = chance.hash({length: 40})
//makes two hashes
console.log(1)
console.log(2)
//logs the two hashes
var out1 = new Chance(1);
var out2 = new Chance(2);
//uses the two hashes above to make new numbers
console.log(out1.random());
console.log(out2.random());
//logs the new numbers
var roundOutcome = out1 + out2;
// Above is where the issue happenes.
console.log(roundOutcome)
//this is where it puts the [object Object][object Object] in console
它应该添加两个数字。我真的不知道在这里做什么。无论如何,它总是说[object Object] [object Object]。
解决方案
var roundOutcome = out1.random() + out2.random();
你没有调用方法。
有趣的事实:如果将两个随机数相加,则结果的随机性不如数字本身。
推荐阅读
- webpack - webpack构建时如何像Nuxt一样做进度条
- javascript - 如何添加新的 js 代码并在 BODY 上运行?
- reactjs - React Speech Recognition - 通过更新状态将文本插入内存
- rpm - 从 rpm 构建 YUM
- python - 如何在选择选项字段中保存/显示 manytomany 字段
- swift - 实体的命名约定及其协议(接口)
- javascript - 如何正确捕获 JavaScript Click 事件以隐藏和显示 Div?
- go - 将字符串转换为自定义结构 Go
- python - 使用 Python 3.8 过滤 API JSON 响应
- powershell - 从 EventViewer 获取具有特定安全 ID 的计算机名称