搜索关键字数组以查看是否有任何字符与用户输入匹配

时间:2019-06-10 19:58:24

标签: javascript arrays

我已经对此进行了测试,并且仅在找到最后一个字符时才变为真。 我希望它与用户类型匹配。

因此,输入是我在用户输入时发生输入更改事件时捕获的内容。 如果输入字符与words数组中的任何字符匹配,则应返回true进行匹配。

示例:

    const input = 'mem';
    const inputLower = input.toLowerCase();
    const words = ['member', 'support', 'life'];
    words.forEach(word => {
      const charList = word.split('');
      console.log('charList = ', charList);
      const isMatch = charList.every(char => { 
        console.log('char = ', char, '  inputLower = ', inputLower);
        return inputLower.includes(char);
      });
      console.log('isMatch = ', isMatch);
    });

1 个答案:

答案 0 :(得分:1)

尝试一下:

$ ldd main
linux-vdso.so.1 (0x00007ffc231f8000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fc47e93f000)
libQt5Sql.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Sql.so.5 (0x00007fc47e6f6000)
libQt5Core.so.5 => /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 (0x00007fc47dfab000)
libmkl_intel_lp64.so => /opt/intel/compilers_and_libraries_2019.4.243/linux/mkl/lib/intel64_lin/libmkl_intel_lp64.so (0x00007fc47d433000)
libmkl_sequential.so => /opt/intel/compilers_and_libraries_2019.4.243/linux/mkl/lib/intel64_lin/libmkl_sequential.so (0x00007fc47be9a000)
libmkl_core.so => /opt/intel/compilers_and_libraries_2019.4.243/linux/mkl/lib/intel64_lin/libmkl_core.so (0x00007fc477bc5000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fc4779a6000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fc477608000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc477404000)
libsqlcipher.so.0 => /usr/lib/x86_64-linux-gnu/libsqlcipher.so.0 (0x00007fc47712d000)
libqsqlite.so => /usr/lib/x86_64-linux-gnu/qt5/plugins/sqldrivers/libqsqlite.so (0x00007fc476f1d000)
libsqlite3.so.0 => /usr/lib/x86_64-linux-gnu/libsqlite3.so.0 (0x00007fc476c14000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc476823000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fc47660b000)
/lib64/ld-linux-x86-64.so.2 (0x00007fc47ecc8000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fc4763ee000)
libicui18n.so.60 => /usr/lib/x86_64-linux-gnu/libicui18n.so.60 (0x00007fc475f4d000)
libicuuc.so.60 => /usr/lib/x86_64-linux-gnu/libicuuc.so.60 (0x00007fc475b96000)
libdouble-conversion.so.1 => /usr/lib/x86_64-linux-gnu/libdouble-conversion.so.1 (0x00007fc475985000)
libglib-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007fc47566e000)
libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007fc4751f6000)
libicudata.so.60 => /usr/lib/x86_64-linux-gnu/libicudata.so.60 (0x00007fc47364d000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fc4733db000)