【发布时间】:2019-09-23 16:48:16
【问题描述】:
我有一个简单的数组,我很难对其进行排序。我在想可能是因为时间格式,所以我不确定如何引用它或如何以这种数组格式对时间进行排序,以便稍后对其进行排序。
//为输入值创建的函数 函数放置(键,值,obj){ 对象 [键] = 值; 返回对象 }
//loads the document from ajax call
function loadDoc() {
//ajax call
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var data = xhttp.responseText;
//input data from webpage into dom element
document.getElementById('next').innerHTML = data
var test = document.getElementsByClassName('gridRow')
//create dict
var new_dict = {}
for(a=0;a<test.length;a++){
if(test[a].children[2].innerText == 'Ready') {
test[a].style.display = 'none';
//drops into the dictionary
put(String(test[a].children[0].innerText).replace(/\n/ig, ''),
test[a].children[3].innerText, new_dict)
}
}
document.getElementById('next').innerHTML = ''
//looping through the dict
for(var index in new_dict) {
document.getElementById('next').innerHTML += ("<br>" + index + " : " +
new_dict[index] + "<br>");
}
输出与名称出现的顺序相同。
【问题讨论】:
-
“我很难排序”你想在哪里排序?
-
您的 for 循环似乎也没有完全显示在这里 - new_dict 数组在哪里声明?
-
请分享创建数组的代码
标签: javascript html arrays loops