UNPKG

0216tool_xiaoye

Version:

叶永洁自定义工具函数库

20 lines 805 B
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>数组取真与分块</title> </head> <body> <script src="../dist/yeyongjie.js"></script> <script type="text/javascript"> // 1. compact(array): 返回数组中所有真值元素组成的新数组 // 2. chunk(array, size): 将数组拆分成多个 size 长度的区块,每个区块组成小数组,整体组成一个二维数组 console.log(xiaoYe.compact([1,0,'',{},false,true])) console.log(xiaoYe.chunk([1,2,3,4,5,6,7,8],2)) console.log(xiaoYe.chunk([1,2,3,4,5,6,7,8],4)) console.log(xiaoYe.chunk([1,2,3,4,5,6,7,8])) console.log(xiaoYe.chunk([1,2,3,4,5,6,7,8],-2)) </script> </body> </html>