Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Retrieve Nested Property Values in JavaScript / Typescript

DZone's Guide to

How to Retrieve Nested Property Values in JavaScript / Typescript

· Performance Zone
Free Resource

Learn how real real-time monitoring is critical for DevOps. Because you can't build what you can't see.

Use the following function to retrieve the value of a property nested within another property in JavaScript...

export function retriveValueFromNestedProperty(objectToIterate: any, propertyName: string): any {

    var array: Array<string> = propertyName.split(".");

    var currentValue: any = objectToIterate[array[0]];

    for (var i = 1; i < array.length; i++) {

        currentValue = currentValue[array[i]];
    }

    return currentValue;
}


Get real-time alerts and visualizations across your cloud infrastructure for real real-time cloud monitoring. Try it FREE now

Topics:

Published at DZone with permission of Merrick Chaffer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}