Friday 2 June 2017

dynamic access of object key in node

I have been trying to access a mongoose returned object in which the first key is the user id which is dynamic. I need to access that key value pair. But I am not able to do it. I have tried bracket notation and also with object.keys(object)[0]

object[user_Id]   // undefined

When tried with data[object.keys(obj)[0]], then

InternalCache {
strictMode: false,
selected: { '592cff36614c8eb40f77f04a': 1, _id: 0 },
shardval: undefined,
saveError: undefined,
validationError: undefined,
adhocPaths: undefined,
removing: undefined,
inserting: undefined,
version: undefined,
getters: {},
_id: undefined,
populate: undefined,
populated: undefined,
wasPopulated: false,
scope: undefined,
activePaths:
StateMachine {
 paths: { '592cff36614c8eb40f77f04a.intake.6-2-2017.drink': 'init' },
 states:
  { ignore: {},
    default: {},
    init: [Object],
    modify: {},
    require: {} },
 stateNames: [ 'require', 'modify', 'init', 'default', 'ignore' ] },
ownerDocument: undefined,
fullPath: undefined,
emitter: EventEmitter { domain: null, _events: {}, _eventsCount: 0, 
_maxListeners: 0 } }

Everthing work fine when working on client side javascript. But when running the same code in node, It is returning such stuff. Help me figure this out

I need to access the first key of the object which is dynamic



via Karthik Dechiraju

No comments:

Post a Comment