Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Javascript hash (node.js)

Javascript hash (node.js)


I am having trouble with accessing a key in a Hash (I am programming in Node.js if that matters).

I have a callback when return a status and a Reply like this:

client.metadata(folder, options, function(status, reply){
  console.log("New hash: " + reply['hash']);

The problem is, reply['hash'] returns undefined. even reply.hash is undefined. How can I access the hash key in reply?

I logged reply and it is:

  "hash": "e533d2c19d236d0d4f84e2a9666659e1",
  "revision": 802,
  "rev": "32203a97cb5",
  "thumb_exists": false,
  "bytes": 0,
  "modified": "Wed, 04 Jan 2012 02:39:18 +0000",
  "path": "/foo",
  "is_dir": true,
  "icon": "folder",
  "root": "dropbox",
  "contents": [],
  "size": "0 bytes"

but when i access hash in reply like in above example, it's:

New hash: undefined

Problem courtesy of: 0xSina


It could be possible that the reply is a string type, and you need to convert it from JSON with a JSON.parse(reply)...

Check out the type of the reply with console.log(typeof reply) and see what it say

Solution courtesy of: Soren


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Javascript hash (node.js)


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription