let nameArray = ['mike', 'john', 'bob', 'jane', 'bob', 'john', 'lee'];
let uniqueNameArray = nameArray.filter((item, index, array) => {
  return array.indexOf(item) === index;
});

const uniqueValues = [...new Set(values)];
var names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice'];

var countedNames = names.reduce(function (allNames, name) { 
  if (name in allNames) {
    allNames[name]++;
  }
  else {
    allNames[name] = 1;
  }
  return allNames;
}, {});
// countedNames is:
// { 'Alice': 2, 'Bob': 1, 'Tiff': 1, 'Bruce': 1 }
function getFirstUser() {
    return getUsers().then(function(users) {
        return users[0].name;
    }).catch(function(err) {
        return {
          name: 'default user'
        };
    });
}
const users = [
  { id: 11, name: 'Adam', age: 23, group: 'editor' },
];

users.map(({id, age, group}) => `\\n${id} ${age} ${group}`).join('')

11 23 editor
const nested = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
let flat = nested.reduce((acc, it) => [...acc, ...it], []);

// flat is [1, 2, 3, 4, 5, 6, 7, 8, 9]

const arrA = [1, 4, 3, 2];
const arrB = [5, 2, 6, 7, 1];

[...new Set([...arrA, ...arrB])]; // returns [1, 4, 3, 2, 5, 6, 7]
function count(arr) {
return arr.reduce((prev, curr) => (prev[curr] = ++prev[curr] || 1, prev), {})
const count1 = function(arr){
return arr.reduce(function(prev, curr){
//return prev[curr] = ++prev[curr] || 1, prev;
prev[curr] = ++prev[curr] || 1;
return prev;
}, {});
}
let isAgeDiverse = function(list) {
  let isTrue = true;
  list.forEach(item => (item.age < 10 || item.age > 90) && (isTrue = false))
  return isTrue;
};
const plucker = field => obj => (obj && obj[field])

const best = { title: '인피니티워', author: 'Peter' }
const books = [{title: '스파이더맨'}, {title: '아이언맨'}, {title: '토르'}]

const extractTitle = plucker('title')
const extractThird = plucker(2)

extractTitle(best) // '인피니티워'
extractThird(books) // {title: '토르'}

JS | 자주쓰는 정규식 (콤마찍기, 숫자만 입력받기 등) / 함수

React TypeScript Cheatsheets | React TypeScript Cheatsheets

nodelist