いつも悩むのでメモ
const data = { last_name: '夏目', first_name: '漱石', created_at: "2017-03-21T12:00:00.000000", updated_at: "2017-03-21T12:00:00.000000", }; const IGNORE_KEYS = [ 'created_at', 'updated_at', ]; const filterIgnoreObject = (data, ignoreKeys) => { const convertedData = {}; for (const key in data) { if (!ignoreKeys.filter(ignoreKey => ignoreKey === key).length) { convertedData[key] = data[key]; } } return convertedData; }; console.info(filterIgnoreObject(data, IGNORE_KEYS)); //-> { last_name: '夏目', first_name: '漱石' }
こんな感じ?
もっとスマートな方法ないかな