474 B
474 B
title, tags, expertise, firstSeen
| title | tags | expertise | firstSeen |
|---|---|---|---|
| Array to flags object | array,object | intermediate | 2022-04-12T05:00:00-04:00 |
Converts an array of strings into an object mapping to true.
- Use
Array.prototype.reduce()to convert the array into an object, where each array value is used as a key whose value is set totrue.
const flags = arr => arr.reduce((acc, str) => ({...acc, [str]: true }), {});
flags(['red', 'green']); // { red: true, green: true }