What is the init property of an array?

Overview

The init property of an array returns an array literal, with each element of the literal being the .init property of the array element.

Syntax

array.init

Return value

It returns an array literal, with each element of the literal initialized.

Example

// import std.stdio
import std.stdio;
// main method
void main(string[] args) {
// create an array
string[3] names;
// add values
names[0] = "Theodore";
names[1] = "John";
names[2] = "Jane";
// print the length of the array
writeln(names.init);
}

Explanation

  • Line 2: We import the std library.
  • Line 5: We create the main method.
  • Lines 9–11: We assign the values to the elements of the array.
  • Line 14: We print the init of the array elements to the console.

Free Resources