1

I need to get a value from the request in Parse.com's javascript cloud code, for a param that I'm fetching dynamically.

It goes like this. I'm getting a list of key objects from the datastore, and for each one I get the actual key:

var key = keyObject.get("Key");
console.log("key = " + key);

The key here is printed correctly. For example it can be IsActionMovie.

Now I need to see if a value for this key exists in my request.

var valueFromRequestForKey = request.params.key;
console.log("valueFromRequestForKey = " + valueFromRequestForKey);

The printout here is always undefined.

Needless to say this works:

var valueFromRequestForKey = request.params.IsActionMovie;

So how do I do it dynamically?

Eddy
  • 3,533
  • 13
  • 59
  • 89

1 Answers1

1

Let´s say the var key has the value IsActionMovie as in your example. With request.params.key you are trying to access a property named key in the params object. (This won´t try to evaluate the key object and access a property by that name)

What you want is to access a property named IsActionMovie in the params object, while writing code that can access any poperty whose name is set in the key var. You can use the square bracket notation for that:

var valueFromRequestForKey = request.params[key];

Fiddle here.

Community
  • 1
  • 1
Daniel J.G.
  • 34,266
  • 9
  • 112
  • 112