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

非破壊的な配列メソッド

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for rakus frontend rakus frontend
April 21, 2024
380

 非破壊的な配列メソッド

Avatar for rakus frontend

rakus frontend

April 21, 2024
Tweet

More Decks by rakus frontend

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) 🤔