javascript - Validate that a set is empty in node.js -


var http = require('http'),     url = require('url'),     route = require('router')(); ... route.get('/{betnametype}', function(req, res) {     var query = url.parse(req.url, true).query;     if (!object.keys(query).length) {        // query string empty     }       else {        // query string set     } } 

hello everyone!.

i'm new javacript / node.js. wonder if possible simplify code. part validates if "query" empty. knowledge did not find easier way

your method works.

in general case of checking object fails on edge case of un-enumerable properties should not issue query string (link source code) , can resolved using object.getownpropertynames instead of object.keys.

given running nodejs , not browser javascript, using object.keys cleanest you're going checking if object has no enumerable properties. thing i'd change explicitly writing .length===0 instead of .length since in fact checking (that object has no keys, , not key falsy)

you might find this question useful.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -