Printing object's keys and values

后端 未结 7 1018
暗喜
暗喜 2021-02-01 06:04

I want to print a key: value pair from javascript object. I can have different keys in my array so cannot hardcode it to object[0].key1

var filters = [{\"user\"         


        
7条回答
  •  遥遥无期
    2021-02-01 06:56

    This is looking for a term property on filters[0]:

    console.log(filters[0].term);
    

    What you actually want to do is use the value of term (in your example that will be "user") as the property identifier:

    console.log(filters[0][term]);
    

提交回复
热议问题