thegreenfrog thegreenfrog - 1 year ago 213
Javascript Question checking array parameter

I am doing a'searchDatabase', keys...)
that is executed whenever a user submits a search. I am currently passing an array of the words submitted called
. However, I do not know how to do the necessary
check(keys, ?)
on the server side. I originally thought that I could do
keys.forEach(function(element) { check(element, String)}
, but i still get a
Did not check() all arguments
error. Should i just pass the submitted search as its original string in the Meteor method call and then break it up on the server? or is there a way to check that keys is an array?

Answer Source

If keys is an array of strings, you can just do:

check(keys, [String]);

Your method would look something like:

  searchDatabase: function(keys) {
    check(keys, [String]);
    // add other method code here
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download