Skip to content

Instantly share code, notes, and snippets.

const shields = {
soccer: {
'AS Monaco': 'https://i.imgur.com/R0LjeFU.png',
'Besiktas': 'https://i.imgur.com/zAhnhFt.png',
'Milan': 'https://i.imgur.com/WiOPhXt.png'
},
baseball: {
'Los Angeles Dodgers': 'https://i.imgur.com/bB0HYgb.png',
'Houston Astros': 'https://i.imgur.com/gwR11oB.png'
},
@Dindaleon
Dindaleon / addRemoveItemInAnArray.js
Last active April 29, 2016 23:29
Add/remove item to/from array without mutating it
// Add item to array
// use concat or spread operator
// Remove item from array
// user slice
// Replace item in array
//
// Source: https://egghead.io/lessons/javascript-redux-avoiding-array-mutations-with-concat-slice-and-spread
@Dindaleon
Dindaleon / removeItemFromObject.js
Last active February 1, 2019 03:33
How to remove an item from object without mutating it
// To remove an item from an array by id:
return state.filter(item => item.id !== action.id)
// To remove a key from an object by id:
let copy = Object.assign({}, state) // assuming you use Object.assign() polyfill!
delete copy[action.id] // shallowly mutating a shallow copy is fine
return copy
// (Bonus) The same with object spread operator proposal: