Concat的第二阵列的JavaScript第一itiem数组的第一个项目 [英] Concat first item of array to first itiem of second array JavaScript

查看:101
本文介绍了Concat的第二阵列的JavaScript第一itiem数组的第一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能Concat的数组的更合理第一项获得第一,第二阵列等等?基本上自动化操作这里CONSOLE.LOG是code:

  $(#键搜索)。在(点击,函数(){
VAR inputVal = $(#输入文本)VAL()。
$ .getJSON(https://en.wikipedia.org/w/api.php?action=opensearch&search=+ inputVal +与&极限= 5和命名空间= 0&放大器;格式= JSON&放大器;回调=? ,功能(JSON){
    VAR ITEMNAME = $。每次(json的[1],功能(我,VAL){
    })
    变种itemDescription = $。每个(JSON [2],功能(I,VAL){
    })
    变种itemLink = $。每个(JSON [3],功能(I,VAL){
    })
    的console.log(ITEMNAME [0] ++ itemDescription [0] ++ itemLink [0]);
    的console.log(ITEMNAME [1] ++ itemDescription [1] ++ itemLink [1]);
    的console.log(ITEMNAME [2] ++ itemDescription [2] ++ itemLink [2]);
    的console.log(ITEMNAME [3] ++ itemDescription [3] ++ itemLink [3]);
    的console.log(ITEMNAME [4] ++ itemDescription [4] ++ itemLink [4]);
    })// EOF的getJSON
}); // EOF按钮点击


解决方案

我相信这是你在找什么:

 为(VAR I = 0; I< itemName.length;我++){
  的console.log(ITEMNAME [I] ++ itemDescription [I] ++ itemLink [I]);
}

how can I concat more rationally first item of array to first of second array and so on? Basically automate console.log here is the code:

$("button#search").on("click", function(){
var inputVal = $("input#text").val();
$.getJSON("https://en.wikipedia.org/w/api.php?action=opensearch&search=" + inputVal +"&limit=5&namespace=0&format=json&callback=?", function(json) {
    var itemName = $.each(json[1], function(i, val){    
    })
    var itemDescription = $.each(json[2], function(i, val){ 
    })
    var itemLink = $.each(json[3], function(i, val){
    })
    console.log(itemName[0] + " " + itemDescription[0] + " " + itemLink[0]);
    console.log(itemName[1] + " " + itemDescription[1] + " " + itemLink[1]);
    console.log(itemName[2] + " " + itemDescription[2] + " " + itemLink[2]);
    console.log(itemName[3] + " " + itemDescription[3] + " " + itemLink[3]);
    console.log(itemName[4] + " " + itemDescription[4] + " " + itemLink[4]);
    })//EOF getJSON
});//EOF button click

解决方案

I believe this is what you are looking for:

for (var i = 0; i < itemName.length; i++) {
  console.log(itemName[i] + " " + itemDescription[i] + " " + itemLink[i]); 
}

这篇关于Concat的第二阵列的JavaScript第一itiem数组的第一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆