Javascript 将提示输入保存到数组中并从中读取
我开始学习javascript,我需要一些帮助。Javascript 将提示输入保存到数组中并从中读取,javascript,arrays,Javascript,Arrays,我开始学习javascript,我需要一些帮助。 我需要将提示输入插入数组并从中读取 var array = [ ["Cat","Black","Awesome"], ["Dog","White","Funny"], ["Chicken","Brown","Delicious"] ]; array.push(prompt("Animal name:")); array.push(prompt("Animal color:")); array.pu
我需要将提示输入插入数组并从中读取
var array = [
["Cat","Black","Awesome"],
["Dog","White","Funny"],
["Chicken","Brown","Delicious"]
];
array.push(prompt("Animal name:"));
array.push(prompt("Animal color:"));
array.push(prompt("Type or something:"));
如果我做了这样的事情,并且我想把它写出来,那么输出是:Cat,Black,Awesome
Dog,White,Funny
Chicken,Brown,Delicious
我的提示输出是(示例):我将如何向数组中插入提示,提示输出如上所示 非常感谢您的回答。
我知道这是一些基本的东西,但我检查了很多网站,找不到答案。您没有将数组放入第一个仅数组的值中,这就是它看起来不一样的原因。您可以简单地将提示值检索到第一个数组中,然后将此数组推送到另一个数组中
var firstArray = [
["Cat","Black","Awesome"],
["Dog","White","Funny"],
["Chicken","Brown","Delicious"]
];
var tempArray = [];
tempArray.push(prompt("Animal name:"));
tempArray.push(prompt("Animal color:"));
tempArray.push(prompt("Type or something:"));
firstArray.push(tempArray);
你不是已经这么做了吗??你已经把它推到了数组中?@OusmaneMahyDiaw我想OP想要推到
array
中的另一个数组中。是的,没错。如何做到这一点,以及如何从中解读?
var firstArray = [
["Cat","Black","Awesome"],
["Dog","White","Funny"],
["Chicken","Brown","Delicious"]
];
var tempArray = [];
tempArray.push(prompt("Animal name:"));
tempArray.push(prompt("Animal color:"));
tempArray.push(prompt("Type or something:"));
firstArray.push(tempArray);