zoukankan      html  css  js  c++  java
  • 学习笔记:_lodash.js常用函数

    _lodash.js 

    文档:https://www.lodashjs.com/docs/4.17.5.html

    _.compact(array)

     创建一个移除了所有假值的数组

    什么是假值?false,null,0,"",undefined,NaN

    _.compact([0, 1, false, 2, '', 3]);
    
    // => [1, 2, 3]

    _.concat(array, [values])

     创建一个用任何数组或值连接的新数组

    var array = [1];
    var other = _.concat(array, 2, [3], [[4]]);
    
    console.log(other);
    // => [1, 2, 3, [4]]
    
    console.log(array);
    // => [1]

    _.indexOf(array, value, [fromIndex=0])

     返回数组中首次匹配的index

    _.indexOf([1, 2, 1, 2], 2);
    // => 1
    
    _.indexOf([1, 2, 1, 2], 2, 2);
    // => 3

    _.join(array, [separator=','])

     将数组中的所有元素转换为由separator分隔的字符串

    _.join(['a', 'b', 'c'], '~');
    // => 'a~b~c'

    _.forEach(collection, [iteratee=_.identity])

     遍历集合

    _([1, 2]).forEach(function(value){
       console.log(value); 
    });
    // => 输出 '1' 和 '2'
    
    _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
       console.log(key); 
    });
    // => 输出 'a' 和 'b' (不保证遍历得顺序)

    (未完)

  • 相关阅读:
    手势识别 ios
    无题
    核心动画笔记
    Quartz2D的学习2
    Quartz2D的学习1
    NSURLsessionTask
    NSURLSession
    POST请求的两种方式
    网络第一天
    NSThread
  • 原文地址:https://www.cnblogs.com/cathy1024/p/10930150.html
Copyright © 2011-2022 走看看