Javascript 如何通过(NODE.JS)从一个数组到另一个数组获取匹配值;
我是JSCRIPT新手,我想尝试一下twitter情绪分析。我有一个名为“disectToWords”的数组,其中包含情感。然后,我有另一个名为“getScoredWords”的数组,其中“AFINN.txt”或“单词的分数”位于该数组中。我想匹配两个数组,以获得匹配的值。我尝试使用filter(),但是,我总是得到一个null/空数组,这意味着,所有数组都是falseJavascript 如何通过(NODE.JS)从一个数组到另一个数组获取匹配值;,javascript,twitter,sentiment-analysis,Javascript,Twitter,Sentiment Analysis,我是JSCRIPT新手,我想尝试一下twitter情绪分析。我有一个名为“disectToWords”的数组,其中包含情感。然后,我有另一个名为“getScoredWords”的数组,其中“AFINN.txt”或“单词的分数”位于该数组中。我想匹配两个数组,以获得匹配的值。我尝试使用filter(),但是,我总是得到一个null/空数组,这意味着,所有数组都是false var getScoredWords = ['abandon', 'abandoned', 'abandons',
var getScoredWords = ['abandon',
'abandoned',
'abandons',
'abducted',
'abduction',
'abductions',
'abhor',
'abhorred',
'abhorrent',
'abhors',
'abilities',
'ability',
'aboard',
'absentee',]
var disectToWords = ['Barry',
'Manilow',
'Singin',
'With',
'The',
'Big',
'Bands',
'abducted',
'aboard',]
var result = getScoredWords.filter(words => disectToWords.includes(words));
但它应该返回“绑架”和“登上”两个词。
请帮帮我,你好,我正在试这个,看起来不错,你可以试试
<script type="text/javascript">
var getScoredWords = ['abandon',
'abandoned',
'abandons',
'abducted',
'abduction',
'abductions',
'abhor',
'abhorred',
'abhorrent',
'abhors',
'abilities',
'ability',
'aboard',
'absentee',]
var disectToWords = ['Barry',
'Manilow',
'Singin',
'With',
'The',
'Big',
'Bands',
'abducted',
'aboard',]
var result = getScoredWords.filter(words => disectToWords.includes(words));
console.log(result);
</script>
var getScoredWords=[“放弃”,
"弃置",,
"放弃",,
“被绑架”,
“绑架”,
“绑架”,
"憎恶",,
"可恶",,
"可恶",,
"憎恶",,
"能力",,
"能力",,
“船上”,
“缺席者”,]
var disectToWords=['Barry',
“Manilow”,
"唱",,
"与",,
"那",,
“大”,
“乐队”,
“被绑架”,
"登船",
var result=getScoredWords.filter(words=>disectToWords.includes(words));
控制台日志(结果);
删除变量名周围的引号,除非代码很好,顺便说一句,我是通过terminal for(MAC)或Cprompt(Win)中的node.js来完成的。我认为alert()不会在终端上运行。但是,谢谢!