Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
常に 20 を超えるが、決して同じ量ではない多数の項目を持つ配列を使用しているとしましょう。その配列を 10 項目だけにトリミングしたいと考えています。ここでの答えは、さまざまなサイズの配列を考慮していません。
これを行う良い方法は何ですか?
Array.slice()で配列をスライスできます:
new_array = old_array.slice(0,10);
フィドル
これにより、配列が所定の位置にトリミングされます。
arr.length = 10;