loading...

Horrible Snippet - Updating an Nested Array With The Spread Operator

twitter logo github logo ・1 min read

Sometimes I like to just sit there and think of weird ways to accomplish things, and sometimes I come up with ideas like this, I think this could be applied to some Functional JS

// I Really dig this one
const foo = {
  bar: {
    baz: [{ changeMe: 'asdf', notMe: 'asdf' }, { changeMe: 'ffff', notMe: 'asdf' }],
  },
};

const newArr = foo.bar.baz.map(baz => ({ ...baz, changeMe: 'swee' }));

const newData = {
  ...foo,
  bar: {
    baz: newArr,
  },
};

console.log('newData', newData.bar.baz);
twitter logo DISCUSS
Classic DEV Post from Feb 16 '18

Homographs, Attack!

Background on a decades-old hack that just keeps coming back.

Sam Clark profile image
I'm not good at programming :(

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️