How to get a subset of a javascript object's properties -


say have object:

elmo = {    color: 'red',   annoying: true,   height: 'unknown',   meta: { one: '1', two: '2'} }; 

i want make new object subset of properties.

 // pseudo code  subset = elmo.slice('color', 'height')   //=> { color: 'red', height: 'unknown' } 

how may achieve this?

using object destructuring , property shorthand

const object = { a: 5, b: 6, c: 7  };  const picked = (({ a, c }) => ({ a, c }))(object);    console.log(picked); // { a: 5, c: 7 }


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -