これは、nodejs を学習するために現在行っている一連のチュートリアルに従っています。developer.github.com のユーザーのリポジトリ情報にアクセスしたい。次のコードを使用しようとすると、エラーが表示されます。
json.forEach(function(repo){ ^ TypeError: Object # has no method 'forEach'
var https=require("https");
var username= "OllieParsley";
var options={
host: "api.github.com",
path: "/users/" +username+ "/repos",
method: "GET",
/*customHeaders: { "User-Agent": "app" }*/
};
var request= https.request(options, function(response){
var body='';
response.on("data", function(chunk){
body+=chunk.toString("utf8");
});
response.on("end", function(){
var repos=[];
var json=JSON.parse(body);
json.forEach(function(repo){
repos.push({
name:repo.name,
description:repo.descripton
});
});
console.log("Repos: ", repos);
});
});
request.end();
オブジェクトにメソッド「forEach」がないとエラーが表示されるのはなぜですか?