몽땅뚝딱 개발자

[Vue.js/라이브러리] lodash 사용해보기(3) - Array 본문

Development/Vue.js

[Vue.js/라이브러리] lodash 사용해보기(3) - Array

레오나르도 다빈츠 2021. 7. 22. 15:28

출처

 

Lodash Documentation

_(value) source Creates a lodash object which wraps value to enable implicit method chain sequences. Methods that operate on and return arrays, collections, and functions can be chained together. Methods that retrieve a single value or may return a primiti

lodash.com

 


 

◽ _.sortedUniq(array)

유니크한 값을 기준으로 정렬한다.

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

 


◽ _.sortedUniqBy(array, [iteratee])

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

 


◽ _.tail(array)

첫번째 엘리먼트를 제외한 엘리먼트를 가져온다.

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

 


◽ _.take(array, [n=1])

인덱스 0부터 시작하여 지정된 인덱스만큼의 배열을 가져온다. 기본값은 1이다.

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

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

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

 


◽ _.takeRight(array, [n=1])

_.take()와 반대로 오른쪽부터 자른다.

 


◽ _.takeRightWhile(array, [predicate=_.identity])

배열 중 조건에 맞는 값을 가져온다.

 


◽ _.takeWhile(array, [predicate=_.identity])

== 추후 정리

 


◽ _.union([arrays])

합집합. 모든 배열에서 순서대로 고유의 값으로 배열을 만들어 반환한다.

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

 


◽ _.unionBy([arrays], [iteratee=_.identity])

_.union과 같으나 두번째 파라미터에서 조건절을 받는다.

 


◽ _.unionWith([arrays], [comparator])

== 추후 정리

 


◽ _.uniq(array)

배열을 받아 중복없는 배열로 반환한다.

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

 


◽ _.uniqBy([arrays], [iteratee=_.identity])

_.uniq와 같으나 두번째 파라미터에서 조건절을 받는다.

 


◽ _.uniqWith([arrays], [comparator])

== 추후 정리

 


_.zip & _.unzip(array)

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

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

 


◽ _.unzipWith(array, [interatee=_.identity])

unzip하는 방법을 두번째 파라미터에 작성한다.

let zipped = _.zip([1, 2], [10, 20], [100, 200]);
// => [[1, 10, 100], [2, 20, 200]]

_.unzipWith(zipped, _.add);
// => [3, 30, 300]

 


◽ _.without(array, [values])

배열에서 지정된 값을 제외한다.

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

 


◽ _.xor([arrays])

배열들의 차집합 값을 반환한다.

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

 


◽ _.xorBy([arrays], [iteratee=_.identity])

_.xor과 동일하나 비교되는 기준을 생성한다.

 


◽ _.xorWith([arrays], [comparator])

== 추후 정리

 


◽ _.zipObject([props=[]], [values=[]])

배열들을 프토퍼티 형태로 반환한다.

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

 


◽ _.zipObjectDeep

== 추후 정리

 


◽ _.zipWith([arrays], [iteratee=_.identity])

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

 

 

Comments