回答編集履歴

2

テキスト追加

2022/09/12 09:51

投稿

退会済みユーザー
test CHANGED
@@ -5,7 +5,7 @@
5
5
  👉 https://codepen.io/su507/pen/rNvLoLd?editors=0012
6
6
 
7
7
  もしくはlodash使ってよければ [_.pickBy](https://lodash.com/docs/#pickBy)で
8
- ```
8
+ ```javascript
9
9
  const result = _.pickBy(obj, (_, key) => arr.includes(+key));
10
10
  ```
11
11
  👉 https://codepen.io/su507/pen/abGZPBR?editors=0012

1

追記

2022/09/12 09:50

投稿

退会済みユーザー
test CHANGED
@@ -3,3 +3,9 @@
3
3
  const result = Object.fromEntries(Object.entries(obj).filter(([key]) => arr.includes(+key)));
4
4
  ```
5
5
  👉 https://codepen.io/su507/pen/rNvLoLd?editors=0012
6
+
7
+ もしくはlodash使ってよければ [_.pickBy](https://lodash.com/docs/#pickBy)で
8
+ ```
9
+ const result = _.pickBy(obj, (_, key) => arr.includes(+key));
10
+ ```
11
+ 👉 https://codepen.io/su507/pen/abGZPBR?editors=0012