Extract certain properties from all objects in array

Use object destructuring to get the properties, and generate a new object using shorthand property names: const dummyArray = [{ “att20”: “att20”, “att30”: “att30”, “att70”: “att70”, “att80”: “att80”}, { “att20”: “att20”, “att30”: “att30”, “att70”: “att70”, “att80”: “att80”}]; const result = dummyArray.map(({ att20, att30, att70, att80 }) => ({ att20, att30, att70, att80 })); console.log(result);

Updating React state when state is an array of objects

Your update function would look like this updateItem(id, itemAttributes) { var index = this.state.items.findIndex(x=> x.id === id); if (index === -1) // handle error else this.setState({ items: [ …this.state.items.slice(0,index), Object.assign({}, this.state.items[index], itemAttributes), …this.state.items.slice(index+1) ] }); } And you use it like this this.updateItem(2, {someattr: ‘a new value’}); Gross right? You’re going to have a big … Read more