In javascript, test for property deeply nested in object graph?

后端 未结 6 927
余生分开走
余生分开走 2020-12-03 23:39

I\'ve got a collection of disparate, complex JSON objects from a CouchDB database. Each contains many levels of nested properties--for example,

tps_report.p         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-04 00:06

    Theres a function defined on this blog to safely read nested properties from a JS object

    It allows you to mine an object for properties... ie.

    safeRead(tps_report, 'personnel_info', 'productivity', 'units_sold');
    

    and if any part of the object chain is null or undefined it returns an empty string....

提交回复
热议问题