TypeError: response.hits[i].hit_set_id.toLowercase is not a function
TypeError: response.hits[i].hit_set_id.toLowercase is not a function
每当我 运行 此代码时,我都会在控制台上收到该错误:
const response = JSON.parse(`{"version":1,"tests":[],"hits":[{"title":"Answer one of our market research surveys (~ 2 to 12 minutes + 1-2 minutes for demographics)","hit_set_id":"36R3RQSDQUGLBEZ545II11576K307C","requester_name":"UXreviewer.io ResearchLab","requester_id":"A1HXBVQANVSV6H","reward":"0.26","description":"Give us your opinion about usability, products, and marketing. The survey itself will be about ~ 2 to 12 minutes; in addition, 1-2 minutes for demographics are required beforehand.","duration_in_seconds":3600,"qualifications":{"project_requirements":[{"qualification_type_id":"00000000000000000071","comparator":"In","worker_action":"AcceptHit","qualification_values":["AL","AM","AN","AQ","AR","AT","AU","BE","BG","BY","CU","CZ","DE","DK","ES","ET","FR","GE","GF","IL","IT","JP","NL","NO","NP","PF","PL","PT","TF","US"],"caller_meets_requirement":true,"qualification_type":{"qualification_type_id":"00000000000000000071","name":"Location","visibility":true,"description":"The Location Qualification represents the location you specified with your mailing address. Some HITs may only be available to residents of particular countries, states, provinces or cities.","has_test":false,"is_requestable":false,"keywords":"location"},"caller_qualification_value":{"integer_value":null,"locale_value":{"country":"US","subdivision":"IL"}}}]},"last_seen":1635091621,"requester_hourly":null}]}
`);
for (let i = 0; i < response.hits.length; i++) {
console.log(response.hits[i]);
console.log(response.hits[i].hit_set_id);
const hitId = response.hits[i].hit_set_id.toLowercase();
const title = response.hits[i].title.toLowercase();
const requesterName = response.hits[i].requester_name.toLowercase();
const requesterId = response.hits[i].requester_id.toLowercase();
}
从响应对象可以看出,response.hits[i].hit_set_id 是一个字符串,但是当我尝试对其调用 toLowerCase() 时,我得到了那个异常。老实说,我不知道发生了什么。
.toLowerCase() 区分大小写。
你在多处拼写 toLowerCase
错误。
for (let i = 0; i < response.hits.length; i++) {
console.log(response.hits[i]);
console.log(response.hits[i].hit_set_id);
const hitId = response.hits[i].hit_set_id.toLowerCase();
const title = response.hits[i].title.toLowerCase();
const requesterName = response.hits[i].requester_name.toLowerCase();
const requesterId = response.hits[i].requester_id.toLowerCase();
}
每当我 运行 此代码时,我都会在控制台上收到该错误:
const response = JSON.parse(`{"version":1,"tests":[],"hits":[{"title":"Answer one of our market research surveys (~ 2 to 12 minutes + 1-2 minutes for demographics)","hit_set_id":"36R3RQSDQUGLBEZ545II11576K307C","requester_name":"UXreviewer.io ResearchLab","requester_id":"A1HXBVQANVSV6H","reward":"0.26","description":"Give us your opinion about usability, products, and marketing. The survey itself will be about ~ 2 to 12 minutes; in addition, 1-2 minutes for demographics are required beforehand.","duration_in_seconds":3600,"qualifications":{"project_requirements":[{"qualification_type_id":"00000000000000000071","comparator":"In","worker_action":"AcceptHit","qualification_values":["AL","AM","AN","AQ","AR","AT","AU","BE","BG","BY","CU","CZ","DE","DK","ES","ET","FR","GE","GF","IL","IT","JP","NL","NO","NP","PF","PL","PT","TF","US"],"caller_meets_requirement":true,"qualification_type":{"qualification_type_id":"00000000000000000071","name":"Location","visibility":true,"description":"The Location Qualification represents the location you specified with your mailing address. Some HITs may only be available to residents of particular countries, states, provinces or cities.","has_test":false,"is_requestable":false,"keywords":"location"},"caller_qualification_value":{"integer_value":null,"locale_value":{"country":"US","subdivision":"IL"}}}]},"last_seen":1635091621,"requester_hourly":null}]}
`);
for (let i = 0; i < response.hits.length; i++) {
console.log(response.hits[i]);
console.log(response.hits[i].hit_set_id);
const hitId = response.hits[i].hit_set_id.toLowercase();
const title = response.hits[i].title.toLowercase();
const requesterName = response.hits[i].requester_name.toLowercase();
const requesterId = response.hits[i].requester_id.toLowercase();
}
从响应对象可以看出,response.hits[i].hit_set_id 是一个字符串,但是当我尝试对其调用 toLowerCase() 时,我得到了那个异常。老实说,我不知道发生了什么。
.toLowerCase() 区分大小写。
你在多处拼写 toLowerCase
错误。
for (let i = 0; i < response.hits.length; i++) {
console.log(response.hits[i]);
console.log(response.hits[i].hit_set_id);
const hitId = response.hits[i].hit_set_id.toLowerCase();
const title = response.hits[i].title.toLowerCase();
const requesterName = response.hits[i].requester_name.toLowerCase();
const requesterId = response.hits[i].requester_id.toLowerCase();
}