简体   繁体   English

JavaScript console.log 显示 Object 作为数组?

[英]JavaScript console.log showing Object as Array?

I am using Firebase Auth to create users and logging the error so that I can display it to the user.我正在使用 Firebase Auth 来创建用户并记录错误,以便我可以将其显示给用户。 This logging is currently in test and goes as follows:此日志记录当前正在测试中,如下所示:

console.log(error);
console.log(typeof(error))

In my console I get the following:在我的控制台中,我得到以下信息:

[Error: [auth/invalid-email] The email address is badly formatted.]
object

Usually when I get an object it is returned in some kind of {} format so I am confused why it is now in seemingly-array-like format?通常当我得到一个 object 时,它会以某种 {} 格式返回,所以我很困惑为什么它现在是类似数组的格式? Could someone shed on light on how this works?有人可以阐明这是如何工作的吗?

In Javascript, arrays are actually objects with some additional functionality.在 Javascript 中,arrays 实际上是具有一些附加功能的对象。 So typeof([]) will return object .所以typeof([])将返回object

It looks like the api is returning an array of Error objects.看起来 api 正在返回一个错误对象数组。 If you wanted to display those errors to the user, you could loop through the returned array and print/concatenate each Error's message property.如果您想向用户显示这些错误,您可以遍历返回的数组并打印/连接每个错误的message属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM