Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js object filter by keys

const obj = { firstName: 'Jean-Luc', lastName: 'Picard', age: 59 };

// { firstName: 'Jean-Luc', lastName: 'Picard' }
Object.keys(obj).
  filter((key) => key.includes('Name')).
  reduce((cur, key) => { return Object.assign(cur, { [key]: obj[key] })}, {});
Source by masteringjs.io #
 
PREVIOUS NEXT
Tagged: #js #object #filter #keys
ADD COMMENT
Topic
Name
4+4 =