Skip to content

Blog Công Nghệ

MENUMENU
  • Trang chủ
  • Giới Thiệu
  • Lập Trình
    • Lập Trình Website
      • Laravel
        • Phân Tích Dự Án
      • PHP
      • SQL
      • HTML
      • CSS
      • Javascipt
      • My Project
      • Wordpress
    • Luyện Skill
    • Lập trình winform
    • CSDL
    • Lập Trình Android
    • Trí tuệ nhân tạo
    • Khai Khoáng Dữ Liệu
    • Arduino
    • Khác
    • Đồ án
  • Phần Mềm
    • Powerpoint
    • Tool
  • Cuộc sống và Giải trí
    • Hợp âm
    • web5ngay - youtube
    • Công Giáo
    • Kỹ Năng Sống
    • Street Workout
  • Danh sách bài viết
  • Guide line
    • Guild line phỏng vấn
    • Guide lines Laravel
    • Guide line Module Frontend
  • Tóm tắt sách
  • Fanpage

Blog Công Nghệ

Nơi chia sẻ kiến thức

Lodash

12 Tháng Hai, 2023 by admin
Lượt xem: 68

Lodash là một thư viện JavaScript mạnh mẽ dùng để xử lý Array, Object, Function, Collection ..v.v. 

Contents

  • 1. Tách ra
    • 1.1 Array
      • 1.1.1 _.chunk
      • 1.1.2 _.unzip
    • 1.2 String
      • 1.2.1 _.words
  • 2. Xóa
    • 2.1 Array
      • 2.1.1 _.compact
      • 2.1.2 _.drop
      • 2.1.3 _.dropRight
      • 2.1.4 _.dropRightWhile
      • 2.1.5 _.dropWhile
      • 2.1.6 _.initial
      • 2.1.7 _.pull
      • 2.1.8 _.pullAll
      • 2.1.9 _.pullAllBy
      • 2.1.10 _.pullAt
      • 2.1.11 _.remove
      • 2.1.12 _.without
      • 2.1.13 _.sortedUniq
      • 2.1.14 _.sortedUniqBy
    • 2.2 String
      • 2.2.1 _.trim
      • 2.2.2 _.trimStart
      • 2.2.3 _.trimEnd
      • 2.2.3 _.truncate
  • 3. Nối
    • 3.1 Array
      • 3.1.1 _.concat
      • 3.1.2 _.join
      • 3.1.3 _.zip
      • 3.1.4 _.zipWith
    • 3.2 Object
      • 3.2.1 _.merge
      • 3.2.2 _.assign
  • 4. So sánh và lấy
    • 4.1 Array
      • 4.1.1 _.difference
      • 4.1.2 _.differenceBy
      • 4.1.3 _.head
      • 4.1.4 _.intersection
      • 4.1.5 _.intersectionBy
      • 4.1.6 _.last
      • 4.1.7 _.lastIndexOf
      • 4.1.8 _.nth
      • 4.1.9 _.slice
      • 4.1.10 _.tail
      • 4.1.11 _.take
      • 4.1.12 _.takeRight
      • 4.1.13 _.takeRightWhile
      • 4.1.14 _.takeWhile
      • 4.1.15 _.xor
      • 4.1.16 _.xorBy
      • 4.1.17 _.xorWith
      • 4.1.18 _.size
      • 4.1.19 _.keyBy
      • 4.1.20 _.reject
    • 4.2 Object
      • 4.2.1 _.functions
      • 4.2.2 _.keys
      • 4.2.3 _.pick
      • 4.2.4 _.pickBy
      • 4.2.5 _.omit
      • 4.2.6 _.omitBy
  • 5. Thay thế
    • 5.1 Array
      • 5.1.1 _.fill
  • 6. Tìm kiếm
    • 6.1 Array
      • 6.1.1 _.findIndex
      • 6.1.2 _.findLastIndex
      • 6.1.3 _.indexOf
      • 6.1.4 _.findKey
  • 7. Hạ cấp
    • 7.1 Array
      • 7.1.1 _.flatten
      • 7.1.2 _.flattenDeep
      • 7.1.3 _.flattenDepth
  • 8. Tạo Object
    • 8.1 Array
      • 8.1.1 _.fromPairs
      • 8.1.2 _.zipObject
      • 8.1.3 _.zipObjectDeep
    • 8.2 Object
      • 8.2.1 _.cloneDeep
  • 9. Nghịch đảo
    • 9.1 Array
      • 9.1.1 _.reverse
  • 10. Duy nhất
    • 10.1 Array
      • 10.1.1 _.union
      • 10.1.2 _.unionBy
      • 10.1.3 _.uniq
      • 10.1.4 _.uniqBy
  • 11. Sắp xếp
    • 11.1 Array
      • 11.1.1 _.sortedIndex
      • 11.1.2 _.sortedIndexBy
      • 11.1.3 _.sortedIndexOf
      • 11.1.4 _.sortedLastIndex
      • 11.1.5 _.sortedLastIndexBy
      • 11.1.6 _.orderBy
      • 11.1.7 _.sortBy
  • 12. Kiểm tra
    • 12.1 _.isNull
    • 12.2 _.isFunction
    • 12.3 _.isUndefined
    • 12.4 _.isNumber
    • 12.5 _.isObject
    • 12.6 _.isDate
    • 12.7 _.isEmpty
    • 12.8 String
      • 12.8.1 _.startsWith
      • 12.8.2 _.endsWith
    • 12.9 Object
      • 12.9.1 _.has
    • 12.10 Object và Array
      • 12.10.1 _.every
      • 12.10.2 _.some
      • 12.10.3 _.includes
      • 12.10.4 _.isEqual
  • 13. Biến đổi
    • 13.1 String
      • 13.1.1 _.camelCase
      • 13.1.2 _.capitalize
      • 13.1.3 _.pad
      • 13.1.4 _.padStart
      • 13.1.5 _.padEnd
      • 13.1.6 _.startCase
      • 13.1.7 _.deburr
  • 14. Lọc
    • 14.1 Array
      • 14.1.1 _.filter
      • 14.1.2 _.find
      • 14.1.3 _.reduce
  • 15. Tiện ích
    • 15.1 _.times
    • 15.2 _.delay
    • 15.3 _.debounce
    • 15.4 _.get
    • 15.5 _.set
  • 16. Lặp
    • 16.1 _.map
    • 16.2 _.mapValues
    • 16.3 _.foreach
  • 17. Gom nhóm
    • 17.1 _.groupBy
  • 18. Toán học
    • 18.1 _.max
    • 18.2 Làm tròn
      • 18.2.1 _.ceil
      • 18.2.2 _.floor
      • 18.2.3 _.round

1. Tách ra

1.1 Array

1.1.1 _.chunk

Tách array chính ra thành những array con với số lượng nhất định.

_.chunk (array, [size=1])

_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]
 
_.chunk(['a', 'b', 'c', 'd'], 3);
// => [['a', 'b', 'c'], ['d']]

1.1.2 _.unzip

Tạo những array theo vị trí của các array.

_.unzip(array)
  
var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
// => [['a', 1, true], ['b', 2, false]]
 
_.unzip(zipped);
// => [['a', 'b'], [1, 2], [true, false]]

1.2 String

1.2.1 _.words

Cắt các chữ trong string bỏ vào mảng.

_.words([string=''], [pattern])

_.words('fred, barney, & pebbles');
// => ['fred', 'barney', 'pebbles']
 
_.words('fred, barney, & pebbles', /[^, ]+/g);
// => ['fred', 'barney', '&', 'pebbles']

2. Xóa

2.1 Array

2.1.1 _.compact

Xóa những dữ liệu là false khỏi array.

Những dữ liệu là false:

  • flase
  • 0
  • empty
  • null
  • undefined
  • NaN
_.compact (array)

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

2.1.2 _.drop

Cắt n phần tử từ vị trí đầu tiên.

_.drop(array, [n=1]) 

_.drop([1, 2, 3]);
// => [2, 3]
 
_.drop([1, 2, 3], 2);
// => [3]
 
_.drop([1, 2, 3], 5);
// => []
 
_.drop([1, 2, 3], 0);
// => [1, 2, 3]

2.1.3 _.dropRight

Cắt n phần tử từ vị trí cuối cùng.

_.dropRight (array, [n=1]) 

_.dropRight([1, 2, 3]);
// => [1, 2]
 
_.dropRight([1, 2, 3], 2);
// => [1]
 
_.dropRight([1, 2, 3], 5);
// => []
 
_.dropRight([1, 2, 3], 0);
// => [1, 2, 3]

2.1.4 _.dropRightWhile

Cắt n phần tử từ vị trí cuối cùng với điều kiện tạo đó.

_.dropRightWhile(array, [predicate=_.identity]) 
  
var users = [
  { 'user': 'barney',  'active': true },
  { 'user': 'fred',    'active': false },
  { 'user': 'pebbles', 'active': false }
];
 
_.dropRightWhile(users, function(o) { return !o.active; });
// => objects for ['barney']
 
// The `_.matches` iteratee shorthand.
_.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
// => objects for ['barney', 'fred']
 
// The `_.matchesProperty` iteratee shorthand.
_.dropRightWhile(users, ['active', false]);
// => objects for ['barney']
 
// The `_.property` iteratee shorthand.
_.dropRightWhile(users, 'active');
// => objects for ['barney', 'fred', 'pebbles']

2.1.5 _.dropWhile

Cắt n phần tử từ vị trí đầu tiên với điều kiện tạo đó.

_.dropWhile(array, [predicate=_.identity]) 

var users = [
  { 'user': 'barney',  'active': false },
  { 'user': 'fred',    'active': false },
  { 'user': 'pebbles', 'active': true }
];
 
_.dropWhile(users, function(o) { return !o.active; });
// => objects for ['pebbles']
 
// The `_.matches` iteratee shorthand.
_.dropWhile(users, { 'user': 'barney', 'active': false });
// => objects for ['fred', 'pebbles']
 
// The `_.matchesProperty` iteratee shorthand.
_.dropWhile(users, ['active', false]);
// => objects for ['pebbles']
 
// The `_.property` iteratee shorthand.
_.dropWhile(users, 'active');
// => objects for ['barney', 'fred', 'pebbles']

2.1.6 _.initial

Bỏ phần tử cuối cùng của mảng.

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

2.1.7 _.pull

Xóa các item có giá trị bằng với item value khỏi mảng.

_.pull(array, [values])
  
var array = ['a', 'b', 'c', 'a', 'b', 'c'];
 
_.pull(array, 'a', 'c');
console.log(array);
// => ['b', 'b']

2.1.8 _.pullAll

Giống _.pull nhưng value dạng array.

_.pullAll(array, values)
  
var array = ['a', 'b', 'c', 'a', 'b', 'c'];
 
_.pullAll(array, ['a', 'c']);
console.log(array);
// => ['b', 'b']

2.1.9 _.pullAllBy

Giống _.pull nhưng kèm điều kiện.

_.pullAllBy(array, values, [iteratee=_.identity])
  
var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
 
_.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
console.log(array);
// => [{ 'x': 2 }]

2.1.10 _.pullAt

Loại bỏ item tại các index.

_.pullAt(array, [indexes])
  
var array = ['a', 'b', 'c', 'd'];
var pulled = _.pullAt(array, [1, 3]);
 
console.log(array);
// => ['a', 'c']
 
console.log(pulled);
// => ['b', 'd']

2.1.11 _.remove

Xóa theo điều kiến. Xóa luôn item trong array gốc.

_.remove(array, [predicate=_.identity])
  
var array = [1, 2, 3, 4];
var evens = _.remove(array, function(n) {
  return n % 2 == 0;
});
 
console.log(array);
// => [1, 3]
 
console.log(evens);
// => [2, 4]

2.1.12 _.without

Xóa item có trong mảng giống với các value.

_.without(array, [values])
  
_.without([2, 1, 2, 3], 1, 2);
// => [3]

2.1.13 _.sortedUniq

Bỏ phần tử trùng, tối ưu hóa cho mảng đã sắp xếp.

_.sortedUniq(array)
  
_.sortedUniq([1, 1, 2]);
// => [1, 2]

2.1.14 _.sortedUniqBy

Bỏ phần tử trùng, tối ưu hóa cho mảng đã sắp xếp. Nhưng có thêm điều kiện.

_.sortedUniqBy(array, [iteratee])
  
_.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
// => [1.1, 2.3]

2.2 String

2.2.1 _.trim

Bỏ khoảng trắng hai đầu.

_.trim([string=''], [chars=whitespace])
  
_.trim('  abc  ');
// => 'abc'
 
_.trim('-_-abc-_-', '_-');
// => 'abc'
 
_.map(['  foo  ', '  bar  '], _.trim);
// => ['foo', 'bar']

2.2.2 _.trimStart

Bỏ khoảng trắng bên trái.

_.trimStart([string=''], [chars=whitespace])
  
_.trimStart('  abc  ');
// => 'abc  '
 
_.trimStart('-_-abc-_-', '_-');
// => 'abc-_-'

2.2.3 _.trimEnd

Bỏ khoảng trắng bên phải.

_.trimEnd([string=''], [chars=whitespace])
  
_.trimEnd('  abc  ');
// => '  abc'
 
_.trimEnd('-_-abc-_-', '_-');
// => '-_-abc'

2.2.3 _.truncate

Cắt string và thêm dấu “…” vào nếu srting dài quá length.

_.truncate([string=''], [options={}])
  
_.truncate('hi-diddly-ho there, neighborino');
// => 'hi-diddly-ho there, neighbo...'
 
_.truncate('hi-diddly-ho there, neighborino', {
  'length': 24,
  'separator': ' '
});
// => 'hi-diddly-ho there,...'
 
_.truncate('hi-diddly-ho there, neighborino', {
  'length': 24,
  'separator': /,? +/
});
// => 'hi-diddly-ho there...'
 
_.truncate('hi-diddly-ho there, neighborino', {
  'omission': ' [...]'
});
// => 'hi-diddly-ho there, neig [...]'

3. Nối

3.1 Array

3.1.1 _.concat

Nối các phần tử của một hoặc nhiều mảng vào mảng khác.

_.concat (array, [values])  

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

3.1.2 _.join

Nối các phần tử lại bằng ký tự gì đó.

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

3.1.3 _.zip

Gom những vị trí lại thành một mảng.

_.zip([arrays])
  
_.zip(['a', 'b'], [1, 2], [true, false]);
// => [['a', 1, true], ['b', 2, false]]

3.1.4 _.zipWith

Giống trên nhưng có xử lý thêm điều kiện gì đó.

_.zipWith([arrays], [iteratee=_.identity])
  
_.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  return a + b + c;
});
// => [111, 222]

3.2 Object

3.2.1 _.merge

Gộp object thành 1 object, không ghi đè undefined.

_.merge(object, [sources])
  
var object = {
  'a': [{ 'b': 2 }, { 'd': 4 }]
};
 
var other = {
  'a': [{ 'c': 3 }, { 'e': 5 }]
};
 
_.merge(object, other);
// => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }

3.2.2 _.assign

Gộp object thành 1 object, có ghi đè undefined.

_.assign(object, [sources])
  
function Foo() {
  this.a = 1;
}
 
function Bar() {
  this.c = 3;
}
 
Foo.prototype.b = 2;
Bar.prototype.d = 4;
 
_.assign({ 'a': 0 }, new Foo, new Bar);
// => { 'a': 1, 'c': 3 }

4. So sánh và lấy

4.1 Array

4.1.1 _.difference

Lấy các item có trong mảng này mà không có không mảng kia.

_.difference (array, [values])  

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

4.1.2 _.differenceBy

Tương tự ._difference nhưng nó sẽ áp dụng tham số thứ 3 apply vào hoặc làm điều kiện so sánh.

_.differenceBy(array, [values], [iteratee=_.identity])

_.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [1.2]
	/* giải thích
		Hàm Math.floor => bỏ dấu thập phân
    	=> [2, 1] compare [2, 3]
        => difference [1]
        => result tương ứng là [1.2]
    */
 
// The `_.property` iteratee shorthand.
_.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
// => [{ 'x': 2 }]
	/* giải thích
		Chọn các phần tử có thuộc tính 'x'
        => result // => [{ 'x': 2 }]
    */

4.1.3 _.head

Lấy phần tử đầu tiên của mảng.

Giống với _.first(array)

_.head(array)

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

4.1.4 _.intersection

Lấy những phần tử giống nhau của các mảng.

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

4.1.5 _.intersectionBy

Giống intersection nhưng nó sẽ áp dụng tham số thứ 3 apply vào hoặc làm điều kiện so sánh.

_.intersectionBy([arrays], [iteratee=_.identity])
  
_.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [2.1]
 
// The `_.property` iteratee shorthand.
_.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }]

4.1.6 _.last

Lấy phần tử cuối cùng của array.

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

4.1.7 _.lastIndexOf

Tìm phần tử cuối cùng giống value search.

_.lastIndexOf(array, value, [fromIndex=array.length-1])
  
_.lastIndexOf([1, 2, 1, 2], 2);
// => 3
 
// Search from the `fromIndex`.
_.lastIndexOf([1, 2, 1, 2], 2, 2);
// => 1

4.1.8 _.nth

Lấy phần tử thứ i của array.

_.nth(array, [n=0])
  
var array = ['a', 'b', 'c', 'd'];
 
_.nth(array, 1);
// => 'b'
 
_.nth(array, -2);
// => 'c';

4.1.9 _.slice

Lấy từ đâu tới đâu, không bao gồm phần tử cuối.

_.slice(array, [start=0], [end=array.length])

4.1.10 _.tail

Lấy tất cả nhưng bỏ phần tử đầu.

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

4.1.11 _.take

Tạo một mảng với n phần tử cắt từ vị trí đầu tiên.

_.take(array, [n=1])
  
_.take([1, 2, 3]);
// => [1]
 
_.take([1, 2, 3], 2);
// => [1, 2]
 
_.take([1, 2, 3], 5);
// => [1, 2, 3]
 
_.take([1, 2, 3], 0);
// => []

4.1.12 _.takeRight

Tạo một mảng với n phần tử cắt từ vị trí cuối cùng.

_.takeRight(array, [n=1])
  
_.takeRight([1, 2, 3]);
// => [3]
 
_.takeRight([1, 2, 3], 2);
// => [2, 3]
 
_.takeRight([1, 2, 3], 5);
// => [1, 2, 3]
 
_.takeRight([1, 2, 3], 0);
// => []

4.1.13 _.takeRightWhile

Lấy các phần tử theo điều kiện từ vị trí cuối.

_.takeRightWhile(array, [predicate=_.identity])
  
var users = [
  { 'user': 'barney',  'active': true },
  { 'user': 'fred',    'active': false },
  { 'user': 'pebbles', 'active': false }
];
 
_.takeRightWhile(users, function(o) { return !o.active; });
// => objects for ['fred', 'pebbles']
 
// The `_.matches` iteratee shorthand.
_.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
// => objects for ['pebbles']
 
// The `_.matchesProperty` iteratee shorthand.
_.takeRightWhile(users, ['active', false]);
// => objects for ['fred', 'pebbles']
 
// The `_.property` iteratee shorthand.
_.takeRightWhile(users, 'active');
// => []

4.1.14 _.takeWhile

Lấy các phần tử theo điều kiện bắt đầu từ vị trí đầu tiên.

_.takeWhile(array, [predicate=_.identity])
  
var users = [
  { 'user': 'barney',  'active': false },
  { 'user': 'fred',    'active': false },
  { 'user': 'pebbles', 'active': true }
];
 
_.takeWhile(users, function(o) { return !o.active; });
// => objects for ['barney', 'fred']
 
// The `_.matches` iteratee shorthand.
_.takeWhile(users, { 'user': 'barney', 'active': false });
// => objects for ['barney']
 
// The `_.matchesProperty` iteratee shorthand.
_.takeWhile(users, ['active', false]);
// => objects for ['barney', 'fred']
 
// The `_.property` iteratee shorthand.
_.takeWhile(users, 'active');
// => []

4.1.15 _.xor

Lấy những item khác nhau của những array.

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

4.1.16 _.xorBy

Giống trên nhưng có xử lý thêm gì đó.

_.xorBy([arrays], [iteratee=_.identity])
  
_.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [1.2, 3.4]
 
// The `_.property` iteratee shorthand.
_.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 2 }]

4.1.17 _.xorWith

Giống trên nhưng có thêm điều kiện.

_.xorWith([arrays], [comparator])
  
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
 
_.xorWith(objects, others, _.isEqual);
// => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]

4.1.18 _.size

Giống trên nhưng có thêm điều kiện.

_.size(collection)
  
_.size([1, 2, 3]);
// => 3
 
_.size({ 'a': 1, 'b': 2 });
// => 2
 
_.size('pebbles');
// => 7

4.1.19 _.keyBy

Lấy dữ liệu dễ hơn dạng mảng và object.

_.keyBy(collection, [iteratee=_.identity])
  
var array = [
  { 'dir': 'left', 'code': 97 },
  { 'dir': 'right', 'code': 100 }
];
 
_.keyBy(array, function(o) {
  return String.fromCharCode(o.code);
});
// => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
 
_.keyBy(array, 'dir');
// => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }

4.1.20 _.reject

Trả về array chứa các element không thỏa điều kiện của tham số thứ hai.

_.reject(collection, [predicate=_.identity])
  
var users = [
  { 'user': 'barney', 'age': 36, 'active': false },
  { 'user': 'fred',   'age': 40, 'active': true }
];
 
_.reject(users, function(o) { return !o.active; });
// => objects for ['fred']
 
// The `_.matches` iteratee shorthand.
_.reject(users, { 'age': 40, 'active': true });
// => objects for ['barney']
 
// The `_.matchesProperty` iteratee shorthand.
_.reject(users, ['active', false]);
// => objects for ['fred']
 
// The `_.property` iteratee shorthand.
_.reject(users, 'active');
// => objects for ['barney']

4.2 Object

4.2.1 _.functions

Trả về tên toàn bộ những function của 1 object.

_.functions(object)
  
function Foo() {
  this.a = _.constant('a');
  this.b = _.constant('b');
}
 
Foo.prototype.c = _.constant('c');
 
_.functions(new Foo);
// => ['a', 'b']

4.2.2 _.keys

Trả về toàn bộ key của object.

_.keys(object)
  
function Foo() {
  this.a = 1;
  this.b = 2;
}
 
Foo.prototype.c = 3;
 
_.keys(new Foo);
// => ['a', 'b'] (iteration order is not guaranteed)
 
_.keys('hi');
// => ['0', '1']

4.2.3 _.pick

Chỉ lấy 1 số thuộc tính của object.

_.pick(object, [paths])
  
var object = { 'a': 1, 'b': '2', 'c': 3 };
 
_.pick(object, ['a', 'c']);
// => { 'a': 1, 'c': 3 }

4.2.4 _.pickBy

Chỉ lấy 1 số thuộc tính của object theo điều kiện.

_.pickBy(object, [predicate=_.identity])
  
var object = { 'a': 1, 'b': '2', 'c': 3 };
 
_.pickBy(object, _.isNumber);
// => { 'a': 1, 'c': 3 }

4.2.5 _.omit

Bỏ một số thuộc tính của object, lấy những thuộc tính còn lại.

_.omit(object, [paths])
  
var object = { 'a': 1, 'b': '2', 'c': 3 };
 
_.omit(object, ['a', 'c']);
// => { 'b': '2' }

4.2.6 _.omitBy

Bỏ một số thuộc tính của object theo điều kiện, lấy những thuộc tính còn lại.

_.omitBy(object, [predicate=_.identity])
  
var object = { 'a': 1, 'b': '2', 'c': 3 };
 
_.omitBy(object, _.isNumber);
// => { 'b': '2' }

5. Thay thế

5.1 Array

5.1.1 _.fill

Thay thế thành …(ký tự nào đó) bắt đầu từ đâu đến đâu (không tính end).

_.fill(array, value, [start=0], [end=array.length]) 

var array = [1, 2, 3];
 
_.fill(array, 'a');
console.log(array);
// => ['a', 'a', 'a']
 
_.fill(Array(3), 2);
// => [2, 2, 2]
 
_.fill([4, 6, 8, 10], '*', 1, 3);
// => [4, '*', '*', 10]

6. Tìm kiếm

6.1 Array

6.1.1 _.findIndex

Tìm vị trí của item đầu tiên thỏa điều kiện.

_.findIndex(array, [predicate=_.identity], [fromIndex=0])

var users = [
  { 'user': 'barney',  'active': false },
  { 'user': 'fred',    'active': false },
  { 'user': 'pebbles', 'active': true }
];
 
_.findIndex(users, function(o) { return o.user == 'barney'; });
// => 0
 
// The `_.matches` iteratee shorthand.
_.findIndex(users, { 'user': 'fred', 'active': false });
// => 1
 
// The `_.matchesProperty` iteratee shorthand.
_.findIndex(users, ['active', false]);
// => 0
 
// The `_.property` iteratee shorthand.
_.findIndex(users, 'active');
// => 2

6.1.2 _.findLastIndex

Tìm vị trí của item cuối cùng thỏa điều kiện.

_.findLastIndex(array, [predicate=_.identity], [fromIndex=array.length-1]) 

var users = [
  { 'user': 'barney',  'active': true },
  { 'user': 'fred',    'active': false },
  { 'user': 'pebbles', 'active': false }
];
 
_.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
// => 2
 
// The `_.matches` iteratee shorthand.
_.findLastIndex(users, { 'user': 'barney', 'active': true });
// => 0
 
// The `_.matchesProperty` iteratee shorthand.
_.findLastIndex(users, ['active', false]);
// => 2
 
// The `_.property` iteratee shorthand.
_.findLastIndex(users, 'active');
// => 0

6.1.3 _.indexOf

Search item in array, return index tìm thấy.

_.indexOf(array, value, [fromIndex=0])
  
_.indexOf([1, 2, 1, 2], 2);
// => 1
 
// Search from the `fromIndex`.
_.indexOf([1, 2, 1, 2], 2, 2);
// => 3

6.1.4 _.findKey

Tìm và trả về key của một phần tử.

_.findKey(object, [predicate=_.identity])
  
var users = {
  'barney':  { 'age': 36, 'active': true },
  'fred':    { 'age': 40, 'active': false },
  'pebbles': { 'age': 1,  'active': true }
};
 
_.findKey(users, function(o) { return o.age < 40; });
// => 'barney' (iteration order is not guaranteed)
 
// The `_.matches` iteratee shorthand.
_.findKey(users, { 'age': 1, 'active': true });
// => 'pebbles'
 
// The `_.matchesProperty` iteratee shorthand.
_.findKey(users, ['active', false]);
// => 'fred'
 
// The `_.property` iteratee shorthand.
_.findKey(users, 'active');
// => 'barney'

7. Hạ cấp

7.1 Array

7.1.1 _.flatten

Hạ cấp mảng xuống 1 level.

_.flatten(array) 

_.flatten([1, [2, [3, [4]], 5]]);
// => [1, 2, [3, [4]], 5]

7.1.2 _.flattenDeep

Hạ cấp mảng về level 1.

_.flattenDeep(array) 

_.flattenDeep([1, [2, [3, [4]], 5]]);
// => [1, 2, 3, 4, 5]

7.1.3 _.flattenDepth

Hạ cấp mảng xuống n level.

_.flattenDepth(array, [depth=1]) 

var array = [1, [2, [3, [4]], 5]];
 
_.flattenDepth(array, 1);
// => [1, 2, [3, [4]], 5]
 
_.flattenDepth(array, 2);
// => [1, 2, 3, [4], 5]

8. Tạo Object

8.1 Array

8.1.1 _.fromPairs

Tạo object từ [key, value] trong array.

_.fromPairs(pairs)
  
_.fromPairs([['a', 1], ['b', 2]]);
// => { 'a': 1, 'b': 2 }

8.1.2 _.zipObject

Lấy array 1 làm key,

Lấy array 2 làm value.

_.zipObject(['a', 'b'], [1, 2]);
// => { 'a': 1, 'b': 2 }

8.1.3 _.zipObjectDeep

Giống trên nhưng phức tạp hơn.

_.zipObjectDeep([props=[]], [values=[]])
  
_.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
// => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }

8.2 Object

8.2.1 _.cloneDeep

Tạo object mới ở địa chỉ mới, để khi thay đổi không ảnh hưởng object ban đầu.

_.cloneDeep(value)
  
var objects = [{ 'a': 1 }, { 'b': 2 }];
 
var deep = _.cloneDeep(objects);
console.log(deep[0] === objects[0]);
// => false

9. Nghịch đảo

9.1 Array

9.1.1 _.reverse

Đảo ngược phần tử của mảng.

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

10. Duy nhất

10.1 Array

10.1.1 _.union

Lấy ra những item duy nhất của một hoặc nhiều array.

_.union([arrays])

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

10.1.2 _.unionBy

Lấy ra những item duy nhất của một hoặc nhiều array nhưng có thêm điều kiện.

_.unionBy([arrays], [iteratee=_.identity])
  
_.unionBy([2.1], [1.2, 2.3], Math.floor);
// => [2.1, 1.2]
 
// The `_.property` iteratee shorthand.
_.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }, { 'x': 2 }]

10.1.3 _.uniq

Lấy ra những item duy nhất của một array.

_.uniq(array)
  
_.uniq([2, 1, 2]);
// => [2, 1]

10.1.4 _.uniqBy

Lấy ra những item duy nhất của một array nhưng theo điều kiện.

_.uniqBy(array, [iteratee=_.identity])
 
_.uniqBy([2.1, 1.2, 2.3], Math.floor);
// => [2.1, 1.2]
 
// The `_.property` iteratee shorthand.
_.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }, { 'x': 2 }]

11. Sắp xếp

11.1 Array

11.1.1 _.sortedIndex

Xác định vị trí chèn vào mảng, có giá trị gần với giá trị cần chèn nhất và nhỏ hơn giá trị cần chèn.

_.sortedIndex(array, value)'

_.sortedIndex([30, 50], 40);
// => 1

11.1.2 _.sortedIndexBy

Xác định vị trí chèn vào mảng, có giá trị gần với giá trị cần chèn nhất và nhỏ hơn giá trị cần chèn. Nhưng có thêm điều kiện.

_.sortedIndexBy(array, value, [iteratee=_.identity])
  
var objects = [{ 'x': 4 }, { 'x': 5 }];
 
_.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
// => 0
 
// The `_.property` iteratee shorthand.
_.sortedIndexBy(objects, { 'x': 4 }, 'x');
// => 0

11.1.3 _.sortedIndexOf

Xác định vị trí chèn vào mảng đã được sắp xếp, có giá trị gần với giá trị cần chèn nhất và nhỏ hơn giá trị cần chèn.

_.sortedIndexOf(array, value)
  
_.sortedIndexOf([4, 5, 5, 5, 6], 5);
// => 1

11.1.4 _.sortedLastIndex

Xác định vị trí chèn vào mảng, có giá trị gần với giá trị cần chèn nhất và lớn hơn giá trị cần chèn.

_.sortedLastIndex(array, value)
  
_.sortedLastIndex([4, 5, 5, 5, 6], 5);
// => 4

11.1.5 _.sortedLastIndexBy

Xác định vị trí chèn vào mảng, có giá trị gần với giá trị cần chèn nhất và lớn hơn giá trị cần chèn. Nhưng có thêm điều kiện.

_.sortedLastIndexBy(array, value, [iteratee=_.identity])
  
var objects = [{ 'x': 4 }, { 'x': 5 }];
 
_.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
// => 1
 
// The `_.property` iteratee shorthand.
_.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
// => 1

11.1.6 _.orderBy

Sắp xếp mảng.

_.orderBy(collection, [iteratees=[_.identity]], [orders])
  
var users = [
  { 'user': 'fred',   'age': 48 },
  { 'user': 'barney', 'age': 34 },
  { 'user': 'fred',   'age': 40 },
  { 'user': 'barney', 'age': 36 }
];
 
// Sort by `user` in ascending order and by `age` in descending order.
_.orderBy(users, ['user', 'age'], ['asc', 'desc']);
// => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]

11.1.7 _.sortBy

Sắp xếp collection theo điều kiện.

_.sortBy(collection, [iteratees=[_.identity]])
  
var users = [
  { 'user': 'fred',   'age': 48 },
  { 'user': 'barney', 'age': 36 },
  { 'user': 'fred',   'age': 40 },
  { 'user': 'barney', 'age': 34 }
];
 
_.sortBy(users, [function(o) { return o.user; }]);
// => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
 
_.sortBy(users, ['user', 'age']);
// => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]

12. Kiểm tra

12.1 _.isNull

_.isNull(value)
  
_.isNull(null);
// => true
 
_.isNull(void 0);
// => false

12.2 _.isFunction

_.isFunction(value)
  
_.isFunction(_);
// => true
 
_.isFunction(/abc/);
// => false

12.3 _.isUndefined

_.isUndefined(value)
  
_.isUndefined(void 0);
// => true
 
_.isUndefined(null);
// => false

12.4 _.isNumber

_.isNumber(value)
  
_.isNumber(3);
// => true
 
_.isNumber(Number.MIN_VALUE);
// => true
 
_.isNumber(Infinity);
// => true
 
_.isNumber('3');
// => false

12.5 _.isObject

_.isObject(value)
  
_.isObject({});
// => true
 
_.isObject([1, 2, 3]);
// => true
 
_.isObject(_.noop);
// => true
 
_.isObject(null);
// => false

12.6 _.isDate

_.isDate(value)
  
_.isDate(new Date);
// => true
 
_.isDate('Mon April 23 2012');
// => false

12.7 _.isEmpty

_.isEmpty(value)
  
_.isEmpty(null);
// => true
 
_.isEmpty(true);
// => true
 
_.isEmpty(1);
// => true
 
_.isEmpty([1, 2, 3]);
// => false
 
_.isEmpty({ 'a': 1 });
// => false

12.8 String

12.8.1 _.startsWith

Kiểm tra chuỗi có nằm ở đầu string cần so sánh.

_.startsWith([string=''], [target], [position=0])
  
_.startsWith('abc', 'a');
// => true
 
_.startsWith('abc', 'b');
// => false
 
_.startsWith('abc', 'b', 1);
// => true

12.8.2 _.endsWith

Kiểm tra chuỗi có nằm ở cuối string cần so sánh.

_.endsWith([string=''], [target], [position=string.length])
  
_.endsWith('abc', 'c');
// => true
 
_.endsWith('abc', 'b');
// => false
 
_.endsWith('abc', 'b', 2);
// => true

12.9 Object

12.9.1 _.has

Kiểm tra object có property hay function nào đó không.

_.has(object, path)
  
var object = { 'a': { 'b': 2 } };
var other = _.create({ 'a': _.create({ 'b': 2 }) });
 
_.has(object, 'a');
// => true
 
_.has(object, 'a.b');
// => true
 
_.has(object, ['a', 'b']);
// => true
 
_.has(other, 'a');
// => false

12.10 Object và Array

12.10.1 _.every

true => nếu tất cả phần tử thỏa điều kiện.

_.every(collection, [predicate=_.identity])
  
_.every([true, 1, null, 'yes'], Boolean);
// => false
 
var users = [
  { 'user': 'barney', 'age': 36, 'active': false },
  { 'user': 'fred',   'age': 40, 'active': false }
];
 
// The `_.matches` iteratee shorthand.
_.every(users, { 'user': 'barney', 'active': false });
// => false
 
// The `_.matchesProperty` iteratee shorthand.
_.every(users, ['active', false]);
// => true
 
// The `_.property` iteratee shorthand.
_.every(users, 'active');
// => false

12.10.2 _.some

true => nếu một trong các phần tử thỏa điều kiện.

_.some(collection, [predicate=_.identity])
  
_.some([null, 0, 'yes', false], Boolean);
// => true
 
var users = [
  { 'user': 'barney', 'active': true },
  { 'user': 'fred',   'active': false }
];
 
// The `_.matches` iteratee shorthand.
_.some(users, { 'user': 'barney', 'active': false });
// => false
 
// The `_.matchesProperty` iteratee shorthand.
_.some(users, ['active', false]);
// => true
 
// The `_.property` iteratee shorthand.
_.some(users, 'active');
// => true

12.10.3 _.includes

Kiểm tra giá trị có nằm trong collection không.

_.includes(collection, value, [fromIndex=0])
  
_.includes([1, 2, 3], 1);
// => true
 
_.includes([1, 2, 3], 1, 2);
// => false
 
_.includes({ 'a': 1, 'b': 2 }, 1);
// => true
 
_.includes('abcd', 'bc');
// => true

12.10.4 _.isEqual

Kiểm tra có giống nhau không.

_.isEqual(value, other)
  
var object = { 'a': 1 };
var other = { 'a': 1 };
 
_.isEqual(object, other);
// => true
 
object === other;
// => false

13. Biến đổi

13.1 String

13.1.1 _.camelCase

Chuyển chữ dạng camel case.

_.camelCase([string=''])
  
_.camelCase('Foo Bar');
// => 'fooBar'
 
_.camelCase('--foo-bar--');
// => 'fooBar'
 
_.camelCase('__FOO_BAR__');
// => 'fooBar'

13.1.2 _.capitalize

Viết hoa chữ cái đầu.

_.capitalize([string=''])

_.capitalize('FRED');
// => 'Fred'

13.1.3 _.pad

Bổ sung chữ bằng cách thêm ký tự 2 bên.

_.pad([string=''], [length=0], [chars=' '])
  
_.pad('abc', 8);
// => '  abc   '
 
_.pad('abc', 8, '_-');
// => '_-abc_-_'
 
_.pad('abc', 3);
// => 'abc'

13.1.4 _.padStart

Bổ sung chữ bằng cách thêm ký tự bên trái.

_.padStart([string=''], [length=0], [chars=' '])
  
_.padStart('abc', 6);
// => '   abc'
 
_.padStart('abc', 6, '_-');
// => '_-_abc'
 
_.padStart('abc', 3);
// => 'abc'

13.1.5 _.padEnd

Bổ sung chữ bằng cách thêm ký tự bên phải.

_.padEnd([string=''], [length=0], [chars=' '])
  
_.padEnd('abc', 6);
// => 'abc   '
 
_.padEnd('abc', 6, '_-');
// => 'abc_-_'
 
_.padEnd('abc', 3);
// => 'abc'

13.1.6 _.startCase

Viết hoa chữ cái đầu mỗi chữ.

_.startCase([string=''])
  
_.startCase('--foo-bar--');
// => 'Foo Bar'
 
_.startCase('fooBar');
// => 'Foo Bar'
 
_.startCase('__FOO_BAR__');
// => 'FOO BAR'

13.1.7 _.deburr

Chuyển chữ có dấu thành chữ không dấu.

_.deburr([string=''])
  
_.deburr('déjà vu');
// => 'deja vu'

14. Lọc

14.1 Array

14.1.1 _.filter

Lọc ra item theo điều kiện.

_.filter(collection, [predicate=_.identity])
  
var users = [
  { 'user': 'barney', 'age': 36, 'active': true },
  { 'user': 'fred',   'age': 40, 'active': false }
];
 
_.filter(users, function(o) { return !o.active; });
// => objects for ['fred']
 
// The `_.matches` iteratee shorthand.
_.filter(users, { 'age': 36, 'active': true });
// => objects for ['barney']
 
// The `_.matchesProperty` iteratee shorthand.
_.filter(users, ['active', false]);
// => objects for ['fred']
 
// The `_.property` iteratee shorthand.
_.filter(users, 'active');
// => objects for ['barney']

14.1.2 _.find

Lọc ra item theo điều kiện. Tương tự hàm _.filter.

_.find(collection, [predicate=_.identity], [fromIndex=0])
  
var users = [
  { 'user': 'barney',  'age': 36, 'active': true },
  { 'user': 'fred',    'age': 40, 'active': false },
  { 'user': 'pebbles', 'age': 1,  'active': true }
];
 
_.find(users, function(o) { return o.age < 40; });
// => object for 'barney'
 
// The `_.matches` iteratee shorthand.
_.find(users, { 'age': 1, 'active': true });
// => object for 'pebbles'
 
// The `_.matchesProperty` iteratee shorthand.
_.find(users, ['active', false]);
// => object for 'fred'
 
// The `_.property` iteratee shorthand.
_.find(users, 'active');
// => object for 'barney'

14.1.3 _.reduce

Lọc giống như filter nhưng trả về dạng object group_by.

Lưu ý: Cần return và đối số thứ ba là {}, là kết quả mặc định khi không có dữ liệu.

_.reduce(collection, [iteratee=_.identity], [accumulator])
  
_.reduce([1, 2], function(sum, n) {
  return sum + n;
}, 0);
// => 3
 
_.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  (result[value] || (result[value] = [])).push(key);
  return result;
}, {});
// => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)

15. Tiện ích

15.1 _.times

Thực hiện số lần cụ thể cho function và trả về array kết quả.

_.times(n, [iteratee=_.identity])
  
_.times(3, String);
// => ['0', '1', '2']
 
 _.times(4, _.constant(0));
// => [0, 0, 0, 0]

15.2 _.delay

Sau một khoảng thời gian, chỉ chạy một lần. Giống setTimeout.

_.delay(func, wait, [args])
  
_.delay(function(text) {
  console.log(text);
}, 1000, 'later');
// => Logs 'later' after one second.

15.3 _.debounce

Gọi một function sau một khoảng thời gian function đó được gọi. Giống setIntervel

_.debounce(func, [wait=0], [options={}])
  
// Avoid costly calculations while the window size is in flux.
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
 
// Invoke `sendMail` when clicked, debouncing subsequent calls.
jQuery(element).on('click', _.debounce(sendMail, 300, {
  'leading': true,
  'trailing': false
}));
 
// Ensure `batchLog` is invoked once after 1 second of debounced calls.
var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
var source = new EventSource('/stream');
jQuery(source).on('message', debounced);
 
// Cancel the trailing debounced invocation.
jQuery(window).on('popstate', debounced.cancel);

15.4 _.get

Lấy dữ liệu mà không bị lỗi undefined.

_.get(object, path, [defaultValue])
  
var object = { 'a': [{ 'b': { 'c': 3 } }] };
 
_.get(object, 'a[0].b.c');
// => 3
 
_.get(object, ['a', '0', 'b', 'c']);
// => 3
 
_.get(object, 'a.b.c', 'default');
// => 'default'

15.5 _.set

Gán dữ liệu mà không bị lỗi undefined.

_.set(object, path, value)
  
var object = { 'a': [{ 'b': { 'c': 3 } }] };
 
_.set(object, 'a[0].b.c', 4);
console.log(object.a[0].b.c);
// => 4
 
_.set(object, ['x', '0', 'y', 'z'], 5);
console.log(object.x[0].y.z);
// => 5

16. Lặp

16.1 _.map

Tạo ra mảng mới sau khi xử lý cái gì đó ở mảng cũ.

_.map(collection, [iteratee=_.identity])
  
function square(n) {
  return n * n;
}
 
_.map([4, 8], square);
// => [16, 64]
 
_.map({ 'a': 4, 'b': 8 }, square);
// => [16, 64] (iteration order is not guaranteed)
 
var users = [
  { 'user': 'barney' },
  { 'user': 'fred' }
];
 
// The `_.property` iteratee shorthand.
_.map(users, 'user');
// => ['barney', 'fred']

16.2 _.mapValues

Trả về object mới từ object cũ sau khi đã xử lý gì đó.

_.mapValues(object, [iteratee=_.identity])
  
var users = {
  'fred':    { 'user': 'fred',    'age': 40 },
  'pebbles': { 'user': 'pebbles', 'age': 1 }
};
 
_.mapValues(users, function(o) { return o.age; });
// => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
 
// The `_.property` iteratee shorthand.
_.mapValues(users, 'age');
// => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)

16.3 _.foreach

Lặp qua các element.

_.forEach(collection, [iteratee=_.identity])
  
_.forEach([1, 2], function(value) {
  console.log(value);
});
// => Logs `1` then `2`.
 
_.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  console.log(key);
});
// => Logs 'a' then 'b' (iteration order is not guaranteed).

17. Gom nhóm

17.1 _.groupBy

Gom nhóm object.

_.groupBy(collection, [iteratee=_.identity])
  
_.groupBy([6.1, 4.2, 6.3], Math.floor);
// => { '4': [4.2], '6': [6.1, 6.3] }
 
// The `_.property` iteratee shorthand.
_.groupBy(['one', 'two', 'three'], 'length');
// => { '3': ['one', 'two'], '5': ['three'] }

18. Toán học

18.1 _.max

Trả về item lớn nhất trong array.

_.max(array)
  
_.max([4, 2, 8, 6]);
// => 8
 
_.max([]);
// => undefined

18.2 Làm tròn

18.2.1 _.ceil

Làm tròn số lên.

5.1 ==> 6

5.6 ==> 6

_.ceil(number, [precision=0])
  
_.ceil(4.006);
// => 5
 
_.ceil(6.004, 2);
// => 6.01
 
_.ceil(6040, -2);
// => 6100

18.2.2 _.floor

Làm tròn số xuống.

5.1 ==> 5

5.6 ==> 5

_.floor(number, [precision=0])
  
_.floor(4.006);
// => 4
 
_.floor(0.046, 2);
// => 0.04
 
_.floor(4060, -2);
// => 4000

18.2.3 _.round

Làm tròn số theo cách thông thường. > 5 lên. < 5 xuống.

5.1 ==> 5

5.6 ==> 6

_.round(number, [precision=0])
  
_.round(4.006);
// => 4
 
_.round(4.006, 2);
// => 4.01
 
_.round(4060, -2);
// => 4100

No related posts.

Post navigation

Previous Post:

Những công nghệ mà tôi muốn tìm hiểu

Next Post:

Các lĩnh vực ngoài chuyên môn

Trả lời Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Ẩn sidebar

Tìm kiếm

Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages

Blog Công Nghệ

Bài viết mới

  • Master typescript
  • Sendmail trong Laravel sử dụng dịch vụ SES, SQS của Amazon
  • Install SSL in Nginx Ubuntu
  • Docker study
  • Bảo vệ: Hướng dẫn code bot Telegram easy game

Lượng truy cập

0074727
Visit Today : 323
Visit Yesterday : 178
This Month : 998
Who's Online : 1
© 2025 Blog Công Nghệ | WordPress Theme by Superbthemes