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,951
  • 35
  • 113
  • 191
  • 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
  • 92,861
  • 21
  • 134
  • 171