array function

cym13 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 31 06:20:03 PDT 2015


On Monday, 31 August 2015 at 13:17:30 UTC, cym13 wrote:
> On Monday, 31 August 2015 at 13:00:49 UTC, Namal wrote:
>> Hey guys, since I am learning D arrays here, can you tell me 
>> the best way to remove an element at the end of an array or at 
>> some index i?
>
> import std.algorithm;
>
> T[] arr;
> arr = arr.remove(index);
>
> http://p0nce.github.io/d-idioms/#Adding-or-removing-an-element-from-arrays

Also, to remove the last element you can use slices:

T[] arr;
arr = arr[0..$-1];


More information about the Digitalmars-d-learn mailing list