LoginSignup
2
1

More than 3 years have passed since last update.

JavaScript の Array を特定の数に分割する関数(chunk)を生やしてみる

Posted at

TL;DR

Array.prototype.chunk = function(size) {
  const new_array = [];
  for(let i = 0; i < this.length; i += size) {
    new_array.push(this.slice(i, i + size));
  };
  return new_array;
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1