次のコード サンプルでは、text_array の各ユーザーをループしながら、テキストから場所を取得しようとしています。テキストから場所を抽出した後、正しいユーザーに対応する配列に値を戻そうとしていますが、「text_array [i] is undefined」というエラーが表示されます。私はこれで何が間違っていますか?
function replace_undefined(text_array) {
var userLocationText = {};
for (i = 0, l = text_array.length; i < l; i++) {
console.log(text_array[i].user);
userLocationText[text_array[i].user] = text_array[i].location;
var text = text_array[i].text;
Placemaker.getPlaces(text, function (o) {
console.log(o);
if ($.isArray(o.match)) {
if (o.match[0].place.name == "Europe" || o.match[0].place.name == "United States") {
var location = o.match[1].place.name;
userLocationText[text_array[i].user] = location;
}
if ($.isArray(o.match)) {
if (o.match[0].place.name !== "Europe") {
var location = o.match[0].place.name;
userLocationText[text_array[i].user] = location;
}
}
} else if (!$.isArray(o.match)) {
var location = o.match.place.name;
userLocationText[text_array[i].user] = location;
}
console.log(text_array);
});
}
}
}
text_array = [{
user: a,
user_id: b,
date: c,
profile_img: d,
text: e,
contentString: f,
url: g,
location: undefined
}, {
user: a,
user_id: b,
date: c,
profile_img: d,
text: e,
contentString: f,
url: g,
location: undefined
}, {
user: a,
user_id: b,
date: c,
profile_img: d,
text: e,
contentString: f,
url: g,
location: undefined
}];