简体   繁体   English

如何通过第一个数组的输入返回第二个数组的值

[英]How to return the value of the second array through the input of the first array

I would like to make a multilingual tool in JavaScript.我想在 JavaScript 中制作一个多语言工具。 I need to match words with their pair in other language.我需要将单词与其他语言中的单词配对。 I would like to use 3 different languages.我想使用 3 种不同的语言。 User inputs names of vegetables, chooses one of several languages and gets the right output.用户输入蔬菜名称,选择几种语言中的一种并获得正确的 output。

 var VegetablesInput = ["tomato", "potato", "cucumber", "carrot"]
 var Italian = ["pomodoro", "patata", "cetriolo", "carota"]
 var Croatian = ["rajčica", "krumpir", "krastavac", "mrkva"]
 var Spanish = ["tomate", "patata", "pepino", "zanahoria"]
 var languageInput = prompt ("Choose Italian, Croatian or Spanish.");
 var languageInput = languageInput.toLowerCase();
   function MatchTheWord (language, word) if (languageInput=="italian" && 
 WordInput 
 == "croatian" && WordInput == "spanish") {
 }

I would like to match an element of the VegetablesInput array with the right word according to the language chosen.我想根据选择的语言将蔬菜输入数组的元素与正确的单词匹配。 But I am not sure how to do it simply by looping through the arrays inside the function.但我不知道如何简单地通过循环通过 function 内的 arrays 来做到这一点。 Any help would be appreciated.任何帮助,将不胜感激。

Hope this help:希望这有帮助:

var Vegetables = {
  it: {
    tomato: "pomodoro",
    potato: "patata",
    cucumber: "cetriolo",
    carrot: "carota",
  },
  cr: {
    tomato: "rajčica",
    potato: "krumpir",
    cucumber: "krastavac",
    carrot: "mrkva",
  },
  sp: {
    tomato: "tomate",
    potato: "patata",
    cucumber: "pepino",
    carrot: "zanahoria",
  },
};
var languageInput = prompt("Choose Italian, Croatian or Spanish.");
var languageInput = languageInput.toLowerCase();
var wordInput = prompt("Choose Word: tomato, potato, cucumber, carrot.");

var translatedWord = Vegetables[languageInput][wordInput]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么返回-1在javascript中排序第二个数组之前的第二个值 - why does return -1 sort the first value of an array before the second in javascript 如何将第一个数组中索引[0]的值赋给第二个数组中的索引[0]? - How to assign a value from index[0] in first array to index[0] in second array? 如何通过输入值检查数组值? - how to check an array value through input value? 如何遍历对象内的数组并将每个数组元素作为第二个键值对及其对应的 ID 返回 - How to traverse through array within an object and return each array element as the second key value pair, along with its' corresponding ID Javascript遍历对象数组并返回第一个值 - Javascript loop through an array of objects and return the first value 如何搜索数组并返回匹配值 - how to search through the array and return the matching value 如何在数组项的第二个对象中查找第一个数组项并从第二个对象返回匹配项 - How to find first array items in second object of array items and return matched items from second object 迭代包含对象的 2 个数组,并使用第一个数组键返回第二个数组的值 - Iterate through 2 arrays containing objects and return the values of a second array using the first arrays keys 返回数组中的第一个和最后一个值 - return first and last value in an array javascript 用第二个数组值替换第一个数组值。 第一个数组长度为 2,第二个数组长度为 7 - javascript replace first array value with second array value. First array length is 2 and second one length is 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM