简体   繁体   English

在复杂对象javascript中找到值

[英]find value in complex object javascript

Basically I have a complex object that retrieves the GPT API (google publisher tag) with this function:基本上我有一个复杂的对象,它用这个函数检索 GPT API(谷歌发布者标签):

googletag.pubads().getSlots();

The object value is something like this:对象值是这样的: 在此处输入图片说明

I need to know if there is a way to compare the value of each property with an X value without getting a problem of recursivity (because the object is huge and i need to to that validation several times) Also, I tried to convert that object into a JSON with JSON.stringify(), and then tried to get the value with a regex, faster, but with this option, I have the problem with Cyclic Object Value.我需要知道是否有一种方法可以将每个属性的值与 X 值进行比较而不会出现递归问题(因为对象很大,我需要多次验证)此外,我尝试转换该对象使用 JSON.stringify() 转换为 JSON,然后尝试使用正则表达式更快地获取该值,但是使用此选项,我遇到了循环对象值的问题。

Any suggestions ?有什么建议 ?

it's more simple.这更简单。 try it to convert it into an array and later use a filter for comparative with your value.尝试将其转换为数组,然后使用过滤器与您的值进行比较。

var objGoogle = {};
var arrayObjectGoogle = [objGoogle];
var filter = arrayObjectGoogle.filter(function(obj){
  obj.yourAttr == yourValue;  });

this will give you a second array with the values found it.这将为您提供第二个数组,其中包含找到的值。 later, index the array for pick up the value do you need.稍后,索引数组以获取您需要的值。

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

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