码迷,mamicode.com
首页 > Web开发 > 详细

js面试题

时间:2017-01-16 20:10:46      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:com   技术   log   images   highlight   doctype   title   body   试题   

技术分享

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script>
   
    function test1(){
    	var jsongood = 
    	{"goods":[{"parentId":"null","productId":1,"name":"商品","amount":"null"},
      {"parentId":1,"productId":11,"name":"水果","amount":"null"},
      {"parentId":1,"productId":12,"name":"饮料","amount":"null"},
      {"parentId":11,"productId":111,"name":"苹果","amount":200},
      {"parentId":11,"productId":112,"name":"香蕉","amount":190},
      {"parentId":11,"productId":113,"name":"梨子","amount":50},
      {"parentId":12,"productId":121,"name":"红茶","amount":200},
      {"parentId":111,"productId":122,"name":"绿茶","amount":200}]}; var len = jsongood.goods.length; var arr = []; for(var i = 0;i < len ;i ++){ if(jsongood.goods[i].name == "水果"){ var aimId = jsongood.goods[i].productId; for(var j = 0;j < len; j ++){ if(jsongood.goods[j].parentId == aimId && jsongood.goods[j].amount > 100){ console.log(jsongood.goods[j].name + "\n" + jsongood.goods[j].productId); arr.push(jsongood.goods[j].productId); } } for(var k = 0;k < arr.length;k ++){ for(var l = 0;l < len ;l ++){ if(jsongood.goods[l].parentId == arr[k]){ console.log(jsongood.goods[l].name + "\n" + jsongood.goods[l].productId); } } } } } } test1(); </script> </head> <body> </body> </html>

  

js面试题

标签:com   技术   log   images   highlight   doctype   title   body   试题   

原文地址:http://www.cnblogs.com/detanx/p/6290662.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!