【JavaScript】 配列やオブジェクトから要素を削除

配列の場合

const deleteFruits =  'Orange';
const fruits = [
  'Apple',
  'Orange',
  'Strawberry'
];
const newFruits = fruits.filter(f => f !== deleteFruits);

オブジェクト配列の場合

const fruitObjects = [
  {id: 1, name: 'Apple', 'amount': 10},
  {id: 2, name: 'Orange', 'amount': 20},
  {id: 2, name: 'Strawberry', 'amount': 30},
];

// index指定で削除
const deleteIndex = 0;
const newFruitObjects = fruitObjects.filter((f, index) => index !== deleteIndex);
// 値指定で削除
const deleteFruit = 'Orange';
const newFruitObjects = fruitObjects.filter(f=> f.name !== deleteFruit);