More than 1 year has passed since last update.
lodash知っとくと捗る
調べたら情報は出てくるけど少しでもその時間を少なくするために備忘録をつける。
新しいものを使うたびに増やしていくスタイルにしよう
・find
- 文字通り検索系。配列を検索する。
- 例)ユーザーIDをキーに
users配列
を探しpayloadでもらったidに該当したオブジェクトを返却する
// payloadがhogeのとき
const user = _.find(this.users, {
userId: payload.userId
})
// => user: {userId: 'hoge', userName: 'fuga'}
・findIndex
-
find
のindex版。こちらはキーに該当するオブジェクトが配列の何番目にあったかを返す。
this.TabIndex = _.findIndex(this.tabs, {
sikCd: node.sikcd
})
// => 1
cloneDeep
- 文字通りディープコピーする。これは結構使う。
- シャローコピーとディープコピーの違いはコチラで。
- 初学者の頃、変更前・変更後の比較の処理でシャローコピーをしていて、値が共有されていてハマりまくっていたのでこれはすぐ覚えた。
let obj = {
title: "HOGE",
description: "FUGA"
}
const obj2 = cloneDeep(obj) // => obj2: {title: "HOGE", description: "FUGA"}
padStart
_.padStart(5, 2, '0'); // => '05'
_.padStart(12, 4, '0'); // => '0012'
_.padStart(100, 2, '0'); // => '100'
times
length = 100
hoge = _.times(length, i => {
// やりたい処理
})

2019年より開始。
都内SES3年目。Nuxt TypeScript golang
はてブ(実績管理用):https://yosuke0517.hatenablog.com/archive
twitter:https://twitter.com/yosuke40102069
2020は「Go」触りたい。
目標:月2件の投稿(Qiitaに限らず)
https://yosuke0517.hatenablog.com/archiveWhy not register and get more from Qiita?
- We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
- you can read useful information later efficiently
By "stocking" the articles you like, you can search right away
Sign upLogin