1

I have had object

dataSourceConfig.transport.read.url

remoteDataSourceConfig: { 
transport: {
        read: {
            url: null, 
        },
    },
},

How to check dataSourceConfig.transport.read.url for undefiend?

Mediator
  • 14,387
  • 34
  • 108
  • 180
  • Check http://stackoverflow.com/questions/3390396/how-to-check-for-undefined-in-javascript – Ankit Jun 14 '13 at 05:29

1 Answers1

4

If I understand your question crrectly, you have to check all the intermediary objects for existence:

if (dataSourceConfig &&
    dataSourceConfig.transport &&
    dataSourceConfig.transport.read &&
    dataSourceConfig.transport.read.url != null
) {
  // is not null or undefined
}

Otherwise you can do something like this:

function isKeySet(obj, key) {
  var keys = key.split('.');
  return keys.reduce(function(o,k){ return o[k]; }, obj) != null;
}

isKeySet(dataSourceConfig, 'transport.read.url'); // false
elclanrs
  • 89,567
  • 21
  • 132
  • 165