Is there a way to duplicate an object with only specified fields? For example:
const a = {
foo: 'bar',
bar: 'baz',
baz: 'foo',
}
// Duplicate of a with only foo and baz properties
const b = { foo: 'bar', baz: 'foo' }
I know I could do
b = {
foo: a.foo,
baz: a.baz,
}
but this seems like a long walk for a short drink of water. What's the quickest way to clone an object as a partial with specified fields?
EDIT: April 8th
I would also like to be able to do this inline, as follows:
const a = {
foo: 'bar',
bar: 'baz',
baz: 'foo',
}
const obj = {
b: { foo: 'bar', baz: 'foo' }
}