访问数组中的对象

时间:2018-02-18 14:29:55

标签: arrays object

我需要到[slug] =>教练...然而阵列号改变了,我需要访问任何数字?我知道我可以使用category-> terms [10] - > slug这个,但是如何访问这个数字?

[categories] => EM_Categories Object
    (
        [is_ms_global:protected] => 1
        [taxonomy:protected] => event-categories
        [meta_key:protected] => event-category
        [terms_name:protected] => categories
        [term_class:protected] => EM_Category
        [terms] => Array
            (
                [10] => EM_Category Object
                    (
                        [option_ms_global] => 1
                        [option_name] => category
                        [taxonomy] => event-categories
                        [id] => 10
                        [term_id] => 10
                        [name] => Coaching
                        [slug] => coaching
                        [term_group] => 0
                        [term_taxonomy_id] => 10
                        [description] => 
                        [parent] => 0
                        [count] => 2
                        [image_url] => 
                        [color] => 

1 个答案:

答案 0 :(得分:0)

我不知道你的语言是哪一种,但在JS中你可以使用find fn和lambda表达式。

在你的例子中

TermsArray.find((x)=> x[slug] == "coaching");

或类似的东西。