【发布时间】:2017-01-10 15:00:47
【问题描述】:
在我检查这篇文章之前:How can I find matching values in two arrays? 但这对我没有帮助。我真的不明白。所以也许如果我在这里解释我的问题,有人可以帮助我解决它。
我有一个学校项目(我应该根据用户的位置、标签、人气分数等来匹配用户。 在对这两个位置使用算法之前,我想要第一个非精确排序。所以基本上我想比较'Paris'和'Paris'这样的两个值)
我的搜索函数返回一个 [],里面有两个 {},所以有两个人与我的第一个搜索值(性别)匹配
我正在使用 Node.js,我的数据库是 MySQL,到目前为止,我的函数正在使用回调和 Promise。
所以这是我的第一个对象(它包含我的搜索者的信息)
[ 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].city == secondArray[0].city.但这里我在第二个数组中有两个 .city 所以它会匹配第一个而不是第二个。 -
@Cruiser 我也尝试过进一步的解决方案,但它不起作用。我做了
for (city in potentialsLocation) { for (city in searcherLoc) { if (city === searcherLoc[0].[city]) { console.log("working ?"); } } }我已经修改了我的数据库中的值,所以它应该可以工作,但是我不能记录任何东西
标签: javascript mysql node.js