我尝试检查是否包含文本console.log(1)或console.log(2)上的任何单词来表示false,但我得到了1,2,1,2,因为它是匹配的,有些失败,但我想如果只包含给定单词中的一个单词,则为ok,但如果不包含false,但我得到true,false
var keywords = ['aslr', 'ida pro', 'gdb', 'windbg', 'immunity debugger', 'boofuzz', 'peach fuzzer', 'winafl', 'python', 'assembly', 'penetration testing', 'exploits', 'metasploit', 'metasploit framework', 'ethical hacker', 'pentest', 'computer security', 'hacking', 'oscp', 'osce', 'osee', 'penetration testing', 'offensive security', 'mitre att&ck', 'vulnerability research', 'vulnerability researcher', 'fuzzing', 'clang', 'llvm', 'address sanitizer', 'afl', 'fuzzers', 'penetration tester']
var data = "a successful cybersecurity consultancy are seeking an experienced penetration tester to join their melbourne practice on a permanent basis. work across a wide portfolio of clients and help them in identifying security vulnerabilities by conducting web application, network security, and wireless penetration testing. key responsibilities/duties: work with a diverse range of customers to identify and solve security problems, both in-person and remotely undertake application, network, and wireless penetration testing and vulnerability assessments prepare high-quality reports detailing security issues, making recommendations and identifying solutions perform social engineering and physical security assessments and/or undertake secure code reviews, where appropriate key requirements: demonstrated experience in penetration testing penetration testing certifications such as oscp, osce, ceh, sans, crest crt or cct a proven passion for cybersecurity with regular attendance at security events and/or memberships to the likes of owasp understanding of information security principles and security technologies 2 + years' work experience in security what the company can offer you: ongoing one-on-one training and development a budget for training courses/certifications flexible working arrangements and the option to work-from-home the opportunity to work in a collaborative environment with experienced security professionals if this position sounds of interest, please click 'apply' or email your cv directly to charlotte@preactarecruitment.com."
for (var i = 0; i < keywords.length; i += 1) {
if (data.indexOf(keywords[i])) {
console.log(1)
}
console.log(2)
}
发布于 2019-10-17 01:12:21
使用通用变量来计算匹配,然后检查变量,而不是记录在循环中。
例如:
let matches = 0;
for (var i = 0; i < keywords.length; i += 1) {
// Note that indexOf returns -1 on failure, not false or zero
if (data.indexOf(keywords[i]) !== -1) {
matches++;
}
}
if(matches) {
console.log(1);
}
else {
console.log(2);
}发布于 2019-10-17 01:21:29
您可以结合使用some和includes来检查keywords中的单词是否在data中,然后记录所需的输出:
var keywords = ['aslr', 'ida pro', 'gdb', 'windbg', 'immunity debugger', 'boofuzz', 'peach fuzzer', 'winafl', 'python', 'assembly', 'penetration testing', 'exploits', 'metasploit', 'metasploit framework', 'ethical hacker', 'pentest', 'computer security', 'hacking', 'oscp', 'osce', 'osee', 'penetration testing', 'offensive security', 'mitre att&ck', 'vulnerability research', 'vulnerability researcher', 'fuzzing', 'clang', 'llvm', 'address sanitizer', 'afl', 'fuzzers', 'penetration tester'];
var data = "a successful cybersecurity consultancy are seeking an experienced penetration tester to join their melbourne practice on a permanent basis. work across a wide portfolio of clients and help them in identifying security vulnerabilities by conducting web application, network security, and wireless penetration testing. key responsibilities/duties: work with a diverse range of customers to identify and solve security problems, both in-person and remotely undertake application, network, and wireless penetration testing and vulnerability assessments prepare high-quality reports detailing security issues, making recommendations and identifying solutions perform social engineering and physical security assessments and/or undertake secure code reviews, where appropriate key requirements: demonstrated experience in penetration testing penetration testing certifications such as oscp, osce, ceh, sans, crest crt or cct a proven passion for cybersecurity with regular attendance at security events and/or memberships to the likes of owasp understanding of information security principles and security technologies 2 + years' work experience in security what the company can offer you: ongoing one-on-one training and development a budget for training courses/certifications flexible working arrangements and the option to work-from-home the opportunity to work in a collaborative environment with experienced security professionals if this position sounds of interest, please click 'apply' or email your cv directly to charlotte@preactarecruitment.com.";
if (keywords.some(word => data.includes(word))) console.log(1);
else console.log(2);
发布于 2019-10-17 01:25:17
您可以使用一个变量来检查找到的关键字的数量,因为您只想要一个,如果count的值超出了1,则中断循环并相应地显示值
var keywords = ['aslr', 'ida pro', 'gdb', 'windbg', 'immunity debugger', 'boofuzz', 'peach fuzzer', 'winafl', 'python', 'assembly', 'penetration testing', 'exploits', 'metasploit', 'metasploit framework', 'ethical hacker', 'pentest', 'computer security', 'hacking', 'oscp', 'osce', 'osee', 'penetration testing', 'offensive security', 'mitre att&ck', 'vulnerability research', 'vulnerability researcher', 'fuzzing', 'clang', 'llvm', 'address sanitizer', 'afl', 'fuzzers','penetration tester']
var data = "a successful cybersecurity consultancy are seeking an experienced penetration tester to join their melbourne practice on a permanent basis. work across a wide portfolio of clients and help them in identifying security vulnerabilities by conducting web application, network security, and wireless penetration testing. key responsibilities/duties: work with a diverse range of customers to identify and solve security problems, both in-person and remotely undertake application, network, and wireless penetration testing and vulnerability assessments prepare high-quality reports detailing security issues, making recommendations and identifying solutions perform social engineering and physical security assessments and/or undertake secure code reviews, where appropriate key requirements: demonstrated experience in penetration testing penetration testing certifications such as oscp, osce, ceh, sans, crest crt or cct a proven passion for cybersecurity with regular attendance at security events and/or memberships to the likes of owasp understanding of information security principles and security technologies 2 + years' work experience in security what the company can offer you: ongoing one-on-one training and development a budget for training courses/certifications flexible working arrangements and the option to work-from-home the opportunity to work in a collaborative environment with experienced security professionals if this position sounds of interest, please click 'apply' or email your cv directly to charlotte@preactarecruitment.com."
let matchCount = 0
for (var i = 0; i < keywords.length; i += 1) {
if (data.includes(keywords[i])) {
matchCount++
}
if (matchCount > 1) break
}
console.log(matchCount === 1 ? 1 : 2)
https://stackoverflow.com/questions/58418469
复制相似问题