JavaScript给出意想不到的结果
我有以下的JavaScript:
#!/usr/bin/env node var fs = require('fs'); var outfile = "hello.txt"; var out = "Modify this script to write out something different.\n"; fs.writeFileSync(outfile, out); console.log("Script: " + __filename + "\nWrote: " + out + "To: " + outfile);
执行以下命令:
node test.js cat hello.txt
我得到以下输出:
[object Object]
我究竟做错了什么?
你得到一个对象作为一个string返回。 你将需要找出对象具有什么属性并返回它们,或者遍历对象并显示属性,或将其转换为string…
console.log(JSON.stringify(objToJson));