Upgrade to Pro — share decks privately, control downloads, hide ads and more …

非破壊的な配列メソッド

rakus frontend
April 21, 2024
190

 非破壊的な配列メソッド

rakus frontend

April 21, 2024
Tweet

Transcript

  1. with() 指定された位置の要素を指定された値で置き換えた新しい配列を返す。 const arr = [1, 2, 3, 4, 5];

    console.log(arr.with(2, 6)); // [1, 2, 6, 4, 5] console.log(arr); // [1, 2, 3, 4, 5] array.with(index, value) 構文 サンプルコード
  2. with() 指定された位置の要素を指定された値で置き換えた新しい配列を返す。 const arr = [1, 2, 3, 4, 5];

    console.log(arr.with(2, 6)); // [1, 2, 6, 4, 5] console.log(arr); // [1, 2, 3, 4, 5] arr.toSpliced(2, 1, 6) 🤔