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");
console.log(types.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?

Answers


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.

EDIT:

Actually your whole function can be reduced to:

var types = function() {
     return [ [ "varchar" ], [ "tinyint" ], [ "tinyblob" ] ];
};

Expanding on the other answer,

assuming you don't use the function anywhere else, you could just write

 module.exports = {
   types: function(){
     return [["varchar"], ["tinyint"], ["tinyblob"]];
   }
 }

Need Your Help

Calculating a row percentage for a specific value in R

r percentage

I've been trying to find a way to calculate the proportion of 1 count in each row in R.

error C1083: Cannot open include file: 'sys/socket.h'

python-2.7 network-programming installation packages

I was installing package pynids(https://jon.oberheide.org/pynids/). I was unale to find sys.h. I am using window7 and python 2.7 and pynids-0.6.1

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.