在 CoffeeScript 中,我试图测试给定的字符串是否是字符串数组的成员。这是我尝试过的(请注意,第一次尝试使用in
运算符,第二次尝试使用运算of
符):
console.log list
list = [ i.courseid for i in list ]
console.log list
console.log courseid
console.log courseid in list
console.log '2904984' in list
console.log 2904984 in list
和:
console.log list
list = [ i.courseid for i in list ]
console.log list
console.log courseid
console.log courseid of list
console.log '2904984' of list
console.log 2904984 of list
编译和运行这两个脚本的结果是:
[ { courseid: '2904984', _id: 5243274d46f7f6d72e000001 },
{ courseid: '2484419', _id: 5245ac6ef3a459ee44000002 },
{ courseid: '2180094', _id: 5245b3fa659d2c2d45000001 },
{ courseid: '2179793', _id: 5245ca8ab405987a49000001 },
{ courseid: '2169240', _id: 5245ca8eb405987a49000002 } ]
2904984,2484419,2180094,2179793,2169240
2484419
false
false
false
当项目是列表的成员时为什么不返回item in list
或item of list
返回的任何线索?true