Monday, 11 May 2015

How to retrieve nested property values in JavaScript / Typescript

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;


  1. or simply use the native reduce function!

    var objectToIterate = {
    prop1: {
    prop2: {
    prop3: 'value'

    var propertyName = 'prop1.prop2.prop3';

    var value = propertyName.split('.').reduce(function (value, current) {
    return value[current];
    }, objectToIterate);

    console.log(value); // 'value'


How to replace the watch battery in Logitech K750 solar power keyboard

Buy this battery Open the battery cover on the back of the keyboard, you’ll need...