你好,我想从两个数组中提取具有相同url的元素。如何循环这两个数组并获取它们的内容,因为它给了我未定义的news_url,并且我认为它输出两次在控制台中的项目。从两个具有相同值的数组中提取元素
function geo(news_array,user_tweets){
console.log(news_array,user_tweets);
for (var x=0; x<user_tweets.length; x++) {
var user = user_tweets[x].user;
var date = user_tweets[x].date;
var profile_img = user_tweets[x].profile_img;
var text = user_tweets[x].text;
var url=user_tweets[x].url;
second(user,date,profile_img,text,url);
}
function second(user,date,profile_img,text,url){
for (var i = 0; i < news_array.length; i++) {
var news_user = news_array[i].news_user;
var news_date = news_array[i].news_date;
var news_profile_img = news_array[i].news_profile_img;
var news_text = news_array[i].news_text;
var news_url=news_array[i].url;
if (url==news_array[i].news_url) {
geocode(user,date,profile_img,text,url,news_user,news_date,news_profile_img,news_text,news_url);
}
}
}
function geocode(user,date,profile_img,text,url,news_user,news_date,news_profile_img,news_text,news_url) {
console.log(url,news_url);
}
}
这两个阵列的结构是什么?您可以console.log它们并显示每个数组的一个或两个项目的输出。 –
我正确缩进你的代码,看起来你错过了一些右花括号。你可以仔细检查一下吗? –
不会有多层次的循环就够了吗? – techfoobar