`
zhangyaochun
  • 浏览: 2601470 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

underscore之size

阅读更多

 

    size

 

     _.size(list)

 

     -------  返回list(数组or对象)的长度 

 

 

  先看一下源码

 

/*
 * @name size
 * @param {Array | Object} obj
 * @info 如果是对象依赖_.keys去算length

*/
_.size = function(obj){
     
      //对参数obj有一个预判
      if(obj == null){
            return 0;
      }

       return (obj.length === + obj.length) ? obj.length : _.keys(obj).length;
}
 

 

 

    实例

 

   

_.size([1,2]); //2
_.size({"name":"zhang","age":"26"}); //2

 

 

   依赖

 

   _.keys http://zhangyaochun.iteye.com/blog/1818574

分享到:
评论

相关推荐

    lodash underscore js库速查手册

    Collection Functions (Arrays or Objects) _.each(list, iterator, [context]) Alias: forEach Iterates over a list of elements, yielding each in turn ..._.size(list) Return the number of values in the list.

    bro-size:通过浏览器、丑化和 gzip 来估计包的大小

    bro-size leap-model.js -x underscore Size -------------------- -------- Uncompressed 31.77 kB Compressed 10.74 kB Compressed + Gzipped 3.74 kB 接受所有 browserify 选项,例如-x从大小估计中排除某些...

    ssd5所有题目

    1. Which of the following expressions evaluates to true in C++ if and only if the index variable i is in bounds for an array of size 10? (a) 0 (b) 0 (c) 0 (d) 0 Feedback: See section 1.3.1 ...

    IE8兼容性和判断IE浏览器版本

    再次,IE8不支持css3的background-size的cover和contain属性,解决办法是使用“background-size polyfill”库来兼容,在所有用到这两个“background-size”属性值的地方,加一行“-ms-behavior”属性。 此外,IE8不...

    acpi控制笔记本风扇转速

    code size, and reduces CPU stack use. (Valery Podrezov + interpreter changes in version 20051202 that eliminated namespace loading during the pass one parse.) Implemented _CID support for PCI Root ...

    springboot整合mybatis-plus实现多表分页查询

    params.put("limit", page.getSize()); return userMapper.selectUsersWithAddressByPage(params); } } ``` 至此,我们就完成了SpringBoot整合MyBatis-Plus实现多表分页查询的基本步骤。通过这种方式,我们可以...

    Javascript函数式编程简单介绍

    随着诸如jQuery、backbone.js、Dojo和underscore.js等库的流行,JavaScript开发者开始更多地采用函数式编程的概念来处理复杂的Web应用程序。JavaScript作为一种动态类型的语言,天然支持高阶函数、闭包和匿名函数,...

    华为c语言编程规范和范例合集

    - 变量名、函数名应具有描述性,使用驼峰式或下划线连接的命名方式,如:camelCase 或 underscore_case。 - 常量应全大写,单词间用下划线分隔,如:MAX_SIZE。 - 避免使用简写和无意义的命名,提高代码可理解性...

    springboot专栏 007springboot整合mybatis-plus增删改查 ModelAndView jsp 分页

    map-underscore-to-camel-case: true global-config: db-config: id-type: auto ``` 然后,创建实体类,例如`User.java`,并继承`BaseEntity`,以便利用Mybatis-Plus的自动维护主键等功能: ```java import ...

    springboot-mybatis-annotation-master.rar

    map-underscore-to-camel-case: true ``` 3. 编写Mapper接口和XML文件:Mybatis允许我们通过编写Mapper接口和对应的XML文件来定义SQL语句。接口中的方法名与XML文件中的SQL标签id对应,方便进行动态SQL操作。 二...

    springboot-mabatisplus-demo.rar

    map-underscore-to-camel-case: true # 自动将下划线转驼峰命名 ``` 二、数据库管理——Durid Durid是阿里巴巴开源的高性能数据库连接池,具备监控分析、连接池管理和SQL执行等功能。在SpringBoot项目中使用Durid...

    项目数据库图

    2. `photo`表:存储照片信息,`photo_i d`为主键,`photo_name`为照片名称,`pattern`可能表示照片的类型或格式,`size`是照片大小,`di scri pti on`为照片描述,`createti me`为创建时间,`abl um_i d`为相册ID,...

    Collections:吓收集的东西,待整理

    8. **Lodash和Underscore库**:这两个库提供了大量实用的集合操作函数,如`_.each()`、`_.filter()`、`_.map()`、`_.reduce()`等,方便开发者处理数组和对象。 综上所述,"Collections:吓收集的东西,待整理"可能...

    Spring Boot集成MyBatis访问数据库的方法

    map-underscore-to-camel-case: true default-fetch-size: 100 default-statement-timeout: 30 ``` 这里,`type-aliases-package`指定了实体类的包路径,`type-handlers-package`为自定义类型处理器的包路径,...

    Ruby on Rails下的图像处理入门教程

    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end end ``` 以上代码会自动为上传的图像创建一个最大尺寸为1024x768的版本,并生成一个200x200像素的缩略图。存储目录按照模型类别、字段...

    对象帮助者

    这些帮助者可以是自定义函数,也可以是某些库(如Lodash、Underscore等)提供的工具集。在深入探讨对象帮助者之前,我们先了解一下JavaScript中的对象。 JavaScript对象是键值对的集合,键通常是字符串,而值可以是...

    C PROGRAMMING TUTORIAL

    - **`sizeof`:** Returns the size of a variable or a data type in bytes. - **`?:`:** Conditional (ternary) operator. #### Operators Precedence in C Operators have a specific precedence that ...

    一个win32下的ARM开源编译器

    size is possible. If you need to avoid the automatic "IT AL" block insertion you can force affected instructions to use the wide encoding with a .W suffix. thumb ;use UAL syntax sub.w r0,r1 ;32-...

Global site tag (gtag.js) - Google Analytics