• Arrays

    An array is like a box with lots of compartments. Each compartment can hold something different. For example, one compartment could hold a number and another could hold a letter. In programming, an array holds information in each compartment so that it can be easily accessed and used.

      • Variable Arrays

      • var fruits = ['apple', 'banana', 'cherry'];
        
        console.log(fruits[1]); // banana
      • void main() {
          var fruits = ['apple', 'banana', 'cherry'];
        
          print(fruits[1]); // banana
        }
        
      • import std.stdio : write;
        import std.string;
        import std.array;
        
        void main()
        {
        	string[] fruits = ["apple", "banana", "cherry"];
        
        	write(fruits[1]); // banana
        }
        
      • <?php
        $fruits = array('apple', 'banana', 'cherry');
        
        print($fruits[1]); // banana
      • fruits = ['apple', 'banana', 'cherry']
        
        print(fruits[1]) # banana
      • package main
        
        import "fmt"
        
        func main() {
        	var fruits = [3]string{"apple", "banana", "cherry"}
        
        	fmt.Println(fruits[1]) // banana
        }