Write / add data in JSON file using Node.js

If this JSON file won’t become too big over time, you should try: Create a JavaScript object with the table array in itvar obj = { table: [] }; Add some data to it, for example:obj.table.push({id: 1, square:2}); Convert it from an object to a string with JSON.stringifyvar json = JSON.stringify(obj); Use fs to write the … Read more

what is the best way to check variable type in javascript

The best way is to use the typeof keyword. The typeof operator maps an operand to one of six values: “string”, “number”, “object”, “function”, “undefined” and “boolean”. The instanceof method tests if the provided function’s prototype is in the object’s prototype chain. This Wikibooks article along with this MDN articles does a pretty good job of summing up JavaScript’s types.