之前我一直在检查这个帖子:How can I find matching values in two arrays? 但它没有帮助我。我真的不明白。所以,如果我在这里解释我的问题,那么有人可以帮助我解决它。在JavaScript数组中匹配值
我有一个学校项目(我应该匹配用户有关他们的位置,标签,流行乐谱等 在使用两个位置的算法之前,我想要一个第一个非精确排序,所以基本上我想比较两个值,如“巴黎”和“巴黎”)
我的搜索函数返回我有两个{}内的[],所以有关于符合我的第一个搜索值的两个人(性别)
我使用Node.js,我的数据库是MySQL,并且我的功能目前使用回调和承诺。
所以这是我的第一个对象(它包含我的搜索者的信息)
[ RowDataPacket {
id: 34,
username: 'natedogg',
latitude: 48.8835,
longitude: 2.3219,
country: 'France',
city: 'Paris',
zipcode: 75017 } ]
这是第二个(包含2个用户)
[ RowDataPacket {
id: 33,
username: 'pablito',
latitude: 48.8921,
longitude: 2.31922,
country: 'France',
city: 'Paris',
zipcode: 75017 },
RowDataPacket {
id: 35,
username: 'tupac',
latitude: 48.8534,
longitude: 2.3488,
country: 'France',
city: 'levallois',
zipcode: 92300 } ]
无我有这个数据怎么能我检查我的搜索者的位置是否是我的otherUsersLocation(即使它们超过1个位置) 感谢您的帮助!
我试过'firstArray [0] ==。市secondArray [0] .city.'但在这里我有thwo。城市的第二个数组,所以它会匹配第一个但不是第二个。 – pkerckho
@Cruiser我也尝试了解决方案,但它不起作用。我做了 'for(city in potentialsLocation){ for(cities in searcherLoc){ if(cities === searcherLoc [0]。[city]){ console.log(“working?”); } } }' }我修改了数据库中的值,所以它应该可以工作,但是我不能记录任何内容 – pkerckho