JS Task2

JS Task2_第1张图片
图片.png
var list=document.getElementById('aqi-list');
       var arr1=new Array();
       for(var i=0;i60){
               arr1.push(aqiData[i]);
           }
       }
       //console.log(arr1);
       for(var i=0;i

比较好的答案:

var cont=document.querySelector("#aqi-list");
        var list=aqiData.filter(function(item,index,array){
            return(item[1]>=60);
        });
        list.sort(function(a,b){
            return b[1]-a[1];
        });
        list.forEach(
                function(item,index,array){

                    var newnode=document.createElement("li");
                    newnode.innerHTML=array[index][0]+":"+array[index][1];
                    cont.appendChild(newnode);

                }
        );

总结:
http://ife.baidu.com/note/detail/id/694
练习写ES6的写法:

 var list=document.getElementById('aqi-list');
       var arr1=new Array();
       for(var i=0;i60){
               arr1.push(aqiData[i]);
           }
       }

转换成:

let list=document.getElementById('aqi-list');
       let arr1=new Array();
       const temp = Array.from(aqiData);
       temp.forEach((item,index) => {
        if(item[1] > 60){
          arr1.push(item)
        }
       })

你可能感兴趣的:(JS Task2)