Skip to main content
Jump to: navigation, search

VJET/Typing Arrays with VJETDocs

{color:#333333}In JavaScript there is the Array type.{color} Below {color:#333333}are examples of using JavaScript Array.{color}

var browsers = ['Firefox', 'Chrome', 'Safari'] ; //< Array 
 var browsers = new Array('Firefox', 'Chrome', 'Safari') ; //< Array 
 var browsers = new Array() ; //< Array
 browsers[0] = 'FireFox' ;
 browsers[1] = 'Chrome' ;
 browsers[2] = 'Safari' ;

What elements you put in the array are up to you. In essence, any JavaScript object can be put in the array. In our previous examples it appears that we only want browser names in our Array. Actually we only want Strings from a typing standpoint. 

{color:#333333}VJETDocs allows you to be very specific about what type you want your array to be. {color}


{color:#333333}{_}Array-Dimension{_}{color}{color:#333333} = "[[" "]]"{color} {color:#333333}Ex: [[]] {color}

{color:#333333}{_}Array-Dimensions{_}{color}{color:#333333} = one or more {color}{color:#333333}{_}Array-Dimension's{_}{color}{color:#333333} back to back{color}

{color:#333333}Ex: [[]][[]] or [[]][[]][[]] {color}

{color:#333333}Array-Type: {color}{color:#333333}{_}Limited-Type-Name{_}{color}{color:#333333} {color}{color:#333333}{_}Array-Dimensions{_}{color}{color:#333333} {color}

{color:#333333}Examples of a Vjet Array Type: String[[]] or Number[[]] or Date[[]][[]]or worker.Task[[]][[]][[]] {color}


{color:#333333}An array with a single [[]] pairs is called a single dimension array. {color}

var out = vjo.sysout.println; 
 var scores = [91, 77, 84] ; //< Number[]
 var names = ['Mark', 'Sean', 'Juan'] ; //< String[] 
 for(var i = 0; i < 3; i++) {
    var name = names[i] ; //< String
    var score = scores[i] ; //< Number
    out(name + ": " + score)

console> {color:#333333}Mark: 91{color} {color:#333333}Sean: 77{color} {color:#333333}Juan: 84 {color}

{color:#333333}It is possible to define arrays of arrays; these are called multi-dimension arrays. Multi-dimension arrays are defined by how many consecutive [[]] pairs. The number of [[]] pairs is often referred to as the n-dimensional array. Thus [[]][[]] means a 2 dimensional array and [[]][[]][[]] means a 3-dimensional array and so on. {color}{color:#333333}For example [[]][[]] is a two-dimensional array. [[]][[]][[]] is a three dimensional array and so on.{color}

{color:#333333}Here is an example of a two dimensional array of Number.{color}

var keys = [ //< Number[][]
 [1, 2, 3],
 [4, 5, 6],
 [7, 8, 9]
 ];
var total = 0 ; //< Number 
 for(var row = 0; row < 3; row++) {
 for (var col = 0; col < 3; col++) {
 total += keys[row][col] ;
 vjo.sysout.println('total: ' + total) ;

{color:#333333}console> total: 45 {color}

{color:#333333}We can have arrays of native types and vjet types. We can even have arrays of functions (we haven't described them yet). {color} {color:#333333}We can even have an array of type-reference (although it may not be too useful).{color}

Back to the top