54 lines
1.2 KiB
Plaintext
54 lines
1.2 KiB
Plaintext
/* Arrays in Jsi */
|
|
// Create a new array with length 0
|
|
var myArray = new Array();
|
|
;myArray;
|
|
|
|
// In Jsi, typeof [] is "array". In ECMAScript, typeof [] is "object"
|
|
;typeof [];
|
|
|
|
// Create a new array with length 5
|
|
var myArray1 = new Array(5);
|
|
;myArray1;
|
|
|
|
// Create an array with 2 members (length is 2)
|
|
var myArray2 = new Array("Item1","Item2");
|
|
;myArray2;
|
|
;myArray2.length;
|
|
|
|
// Create an array with 2 members using an array literal
|
|
var myArray3 = ["Item1", "Item2"];
|
|
;myArray3;
|
|
|
|
// Assign a value to member [2] (length is now 3)
|
|
myArray3[2] = 5;
|
|
;myArray3;
|
|
;myArray3.length;
|
|
|
|
var x = myArray3[2] + myArray3.length; // 8
|
|
;x;
|
|
|
|
// You can also add a member to an array with the push function (length is now 4)
|
|
myArray3.push('Test');
|
|
;myArray3;
|
|
;myArray3.length;
|
|
|
|
// Empty array entries in a literal is a syntax error, elisions not allowed
|
|
//var badSyntax = [1,2,,4];
|
|
|
|
|
|
/*
|
|
=!EXPECTSTART!=
|
|
myArray ==> []
|
|
typeof [] ==> array
|
|
myArray1 ==> [ undefined, undefined, undefined, undefined, undefined ]
|
|
myArray2 ==> [ "Item1", "Item2" ]
|
|
myArray2.length ==> 2
|
|
myArray3 ==> [ "Item1", "Item2" ]
|
|
myArray3 ==> [ "Item1", "Item2", 5 ]
|
|
myArray3.length ==> 3
|
|
x ==> 8
|
|
myArray3 ==> [ "Item1", "Item2", 5, "Test" ]
|
|
myArray3.length ==> 4
|
|
=!EXPECTEND!=
|
|
*/
|