JavaScript数组是否等效于Python的“ if in in list”?
这基本上说明了是非。如果找到该项目,则返回true,否则返回false。您可以使用include在JavaScript数组中实现相同的目的。
示例
以下是代码-
var nameList =
[
"John",
"David",
"Bob",
"Carol",
"Sam"
]
console.log(nameList.includes("Bob"));
console.log(nameList.includes("Adam"));要运行上述程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo286.js。
输出结果
这将在控制台上产生以下输出-
PS C:\Users\Amit\javascript-code> node demo286.js true false
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志