E-ebola virus E-ebola virus - 1 year ago 101
Javascript Question

How return array of arrays in node js?

I have module like this in node js

var types = function (){

var typeList= new Array();
typeList[0] = "varchar";

var numericDTs= new Array();
numericDTs[0] = "tinyint";

var binaryDTs= new Array();
binaryDTs[0] = "tinyblob";

var data = array();
data[0] = typeList;
data[1] = numericDTs;
data[2] = binaryDTs;

return data;

module.exports = {
types: types,

i am calling this module like this

var types = require("./include/types");

i got error like this
500 ReferenceError: array is not defined
no error if i return only types or typeList or binaryDTs.
How return array of arrays in node js?

Answer Source

Your error is here:

var data = array();

Write the following instead:

var date = [];

Actually replace every new Array() with [].

Instead of

var typeList= new Array();
typeList[0] = "varchar";

write var typeList = [ "varchar" ]; and so on.


Actually your whole function can be reduced to:

var types = function() {
     return [ [ "varchar" ], [ "tinyint" ], [ "tinyblob" ] ];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download