[英]Why this array doesnt work map and find?
Im debugging a React app, and I have this element here: 我正在调试一个React应用程序,我在这里有这个元素:
If I try to make a user.matches[1]
the console returns me the element who is in this position. 如果我尝试创建一个
user.matches[1]
则控制台会向我返回处于此位置的元素。
But If I try to make a map or a find in this array, the console says "undefined". 但是,如果我尝试在此数组中进行映射或查找,则控制台会显示“ undefined”。
What Im missing here??? 我在这里缺少什么??? I want to make a for on this object.
我想为此对象做一个。 Why I cant?
为什么我不能?
As said by @CertianPerformance that is not an array. 正如@CertianPerformance所说的,它不是数组。 that is an object.
那是一个对象。 {} not [].
{}不是[]。 What you need to do is count the keys.
您需要做的就是数钥匙。
This can be found here How to list the properties of a JavaScript object? 可以在这里找到如何列出JavaScript对象的属性?
var keys = Object.keys(myObject); var keys = Object.keys(myObject);
then keys would be an array :) 那么键将是一个数组:)
edit: said object instead of array 编辑:表示对象而不是数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.