lodash
Posted gyz418
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章
/node_modules/lodash.template/index.js:1558 throw result; ^ SyntaxError: Unexpected token = 报错解决(代码