Printing object's keys and values

后端 未结 7 1021
暗喜
暗喜 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:47

    You can access the value using array syntax

    var filters = [{"user":"abc"},{"application":"xyz"}];
    console.log(Object.keys(filters[0])[0]); // prints user
    var term = (Object.keys(filters[0])[0]);
    console.log(filters[0][term]);// prints abc
    

提交回复
热议问题