공식문서: https://lodash.com/docs/4.17.15
return: (Array)
let array = [1, 2, 3];
_.fill(array, 0); // array: [0, 0, 0]
_.fill(Array(3), 1); // [1, 1, 1]
_.fill([1, 2, 3, 4], '*', 1, 3) // [1, '*', '*', 4];
return: (number)
비슷한 함수
findLastIndex(https://lodash.com/docs/4.17.15#findLastIndex)
indexOf(https://lodash.com/docs/4.17.15#indexOf)
const arr = {
{ 'name': 'A', 'active': true },
{ 'name': 'B', 'active': true },
{ 'name': 'C', 'active': false }
}
_.findIndex(arr, d => return d.name === 'B'); // 1
_.findIndex(arr, { 'name': 'A', 'active': true}); // 0
_.findIndex(arr, ['active', true]); // 0
return: (*) collection
_.forEach([1, 2], val => console.log(val)) // ouput: 1, 2
_.forEach([{'a': 1 }, { 'b': 2 }], (val, key) => console.log(key)) // output: a, b
return: (Array) new sorted Array
const users = [
{ 'user': 'fred', 'age': 48 },
{ 'user': 'barney', 'age': 36 },
{ 'user': 'fred', 'age': 40 },
{ 'user': 'barney', 'age': 34 }
];
_.sortBy(users, [(d) => d.user]) // return: [['barney', 36], ['barney', 34], ['fred', 48], ['fred',40]]
_.sortBy(users, ['user', 'age']) // return: [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
options.leading = false:
options.maxWait = false: 기다릴 수 있는 최대 시간
options.trailing = true:
return: (Function) new debounced or throttled function
스크롤 휠을 이용한 지도 확대/축소
검색어 입력 시 자동완성 및 연관 검색어 노출
피드 방식의 데이터 노출
// resize 이벤트 유동적 - 마지막 처리
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
// scroll 이벤트 유동적 - 처음 처리
jQuery(window).on('scroll', _.throttle(updatePosition, 100));
args: func의 매개변수
return: (number) timer id
_.delay((text) => console.log('text), 1000, 'later') // output: 1초 후 text 출력
return: value(*) deep cloned value
_.clone(value)
const arr = [1, 2];
let cArr = _.clone(arr);
console.log(arr === cArr); // output: true
cArr = _.cloneDeep(arr);
console.log(arr === cArr); // output: false
이 외에 대부분의 배열, 객체, 데이터를 다루는 js 함수들을 지원하는 것 같다.
필요할 때 docs 참고해서 활용해야겠다!