JavaScript Array Methods in Geogebra
//JavaScript Array Methods
//arr.length
var arr = new Array(2,3,5,8);
alert(arr.length);
//////////////////////////////
//arr.concat();
var mate = ["Algebra", "Geometry"];
var scie = ["Biology", "Chemistry", "Physics"];
var stem= ["Technology","Engineering"];
var courses = stem.concat(mate, scie);
var str="";
for(var i=0;i<courses.length;i++){
str=str+courses[i]+" ";
}
alert(str);
///////////////////////////////////
//arr.indexOf();
var numbers = ["Natural","Whole","Integer","Rational","Real"];
alert("index="+numbers.indexOf("Integer"));
///////////////////////////////////
//arr.join()
var angles = ["Acute", "Obtuse", "Right", "Straight"];
alert(angles.join());
///////////////////////////////////
//arr.lastIndexOf();
var numbers = ["Natural","Whole","Integer","Rational","Real"];
alert("index="+numbers.lastIndexOf("Rational"));
///////////////////////////////////
//arr.pop();
var angles = ["Acute", "Obtuse", "Right", "Straight"];
angles.pop();
alert(angles.join());
///////////////////////////////////
//arr.push();
var numbers = ["Natural","Whole","Integer","Rational","Real"];
numbers.push("Complex");
alert(numbers.join());
///////////////////////////////////
//arr.reverse();
var angles = ["Acute", "Obtuse", "Right", "Straight"];
angles.reverse();
alert(angles.join());
///////////////////////////////////
//arr.shift();
var angles = ["Acute", "Obtuse", "Right", "Straight"];
angles.shift();
alert(angles.join());
///////////////////////////////////
//arr.slice();
var numbers = ["Natural","Whole","Integer","Rational","Real"];
var counting = numbers.slice(1, 3);
alert(counting.join());
///////////////////////////////////
//arr.sort();
var numbers = ["Natural","Whole","Integer","Rational","Real"];
numbers.sort();
alert(numbers.join());
///////////////////////////////////
//arr.splice();
var quadrilaterals = ["Square","Rectangle","Rhombus","Parallelogram"];
quadrilaterals.splice(2, 0, "Trapezium", "Kite");
alert(quadrilaterals.join());
///////////////////////////////////
//arr.toString();
var functions = ["Linear", "Square", "Cube", "Square Root","Absolute Value","Reciprocal"];
alert(functions.toString());
///////////////////////////////////
//arr.unshift();
var matrices=["Null","Row","Column","Square"];
matrices.unshift("Diagonal","Symmetric");
alert(matrices.join());
///////////////////////////////////
//arr.valueOf();
var properties=["Commutative","Associative","Distributive","Identity","Inverse","Closure"];
var p=properties.valueOf();
alert(p.join());