【发布时间】:2016-12-09 21:43:50
【问题描述】:
我目前正处于学习 Javascript 的初级阶段,想知道你如何能够遍历这个数组并将所有数据输出为 html 内容:
var links = new Array(); //Missing this part as code
links[0] = new Array();
links[0]["linkName"] = "W3Schools";
links[0]["linkLogo"] = "http://www.w3schools.com/images/w3schools.png";
links[0]["linkURL"] = "http://www.w3schools.com/";
links[0]["linkDescription"] = "W3Schools is a web developer information website, with tutorials and references relating to web development topics such as HTML, CSS, JavaScript and PHP.";
links[1] = new Array();
links[1]["linkName"] = "Code Academy";
links[1]["linkLogo"] = "";
links[1]["linkURL"] = "https://www.codecademy.com/";
links[1]["linkDescription"] = "Codecademy is an online interactive platform that offers free coding classes in 9 different programming languages.";
links[2] = new Array();
links[2]["linkName"] = "";
links[2]["linkLogo"] = "http://www.w3.org/2008/site/images/logo-w3c-mobile-lg";
links[2]["linkURL"] = "http://www.w3.org/";
links[2]["linkDescription"] = "The World Wide Web Consortium is the main international standards organization for the World Wide Web.";
【问题讨论】:
-
“将所有数据输出为html内容”真的很模糊。此外,在提出 SO 问题之前,请尝试使用谷歌搜索并展示您尝试过的内容。人们很乐意为您提供帮助。
-
这是一个相当奇怪的数据结构,让每个数组项包含一个具有属性的对象不是更容易吗? (我不确定
links[0]["linkName"] = "W3Schools";会按照你的想法做) -
反对你的人是迂腐的白痴,他们对你没有定义“html”和“输出”感到不安。代表他们接受我的道歉。 SO上的大多数人都很棒,整个社区也是如此!给 .forEach 一个 google,JS 中的循环,也许还有一般的 JS 教程!你可能已经深入到了最深处,所以慢慢来,继续编码:) 一切顺利!
-
感谢斯坦的客气话! :) 我很感激!
标签: javascript arrays loops if-statement