首页 > 代码库 > lodash
lodash
lodash常用函数一
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>lodash常用函数</title> </head> <body> <script src="//cdn.bootcss.com/lodash.js/4.16.1/lodash.min.js"></script> <p>1.for 循环 _.times()</p> <script> /*for(let i = 0 ;i <5; i ++){ // }*/ _.times(5,function (i) { // console.log("times: "+i); }) </script> <p>2. json 取数据 _.map()</p> <script> var ownerArr = [ { "owner":"aa", "pets":[{"name":"dog1"},{"name":"dog2"}] }, { "owner":"bb", "pets":[{"name":"dog11"},{"name":"dog12"}] }, ]; // 1 ownerArr.map(function (owner) { return owner.pets[0].name; }); // 2 console.log("json: "+ownerArr.map(owner => owner.pets[0].name)); //3 console.log(‘josn2: ‘ + _.map(ownerArr,‘pets[0].name‘)) </script> <p>3. es6 map复习 map相当于 for 循环 </p> <script> console.log("map1: "+[1, 2, 3].map(x => x * 2)); let arr = [4,5,60].map(x=>x*3); console.log("map2: "+arr); var arr2 = [6,7,8]; for(var i = 0 ;i<arr2.length;i++){ console.log(‘arr2: ‘ + arr2[i]*2); } </script> </body> </html>
lodash
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。