*** JavaScript Objects ***
*** Math ***
// Math members
E
- returns the base of natural logarithms
LN2
- returns the natural logarithm of 2
LN10
- returns the natural logarithm of 10
LOG2E
- returns the base-2 logarithm of E
LOG10E
- returns the base-10 logarithm of E
PI
- returns PI
SQRT1_2
- returns the square root of 0.5
SQRT2
- returns the square root of 2
// Math methods
abs(number)
- returns the absolute value a number
Note + The absolute value of -5 is 5, etc...
acos(number)
- returns the arccosine of a number
Note + returns a radian value, not a degree value...
asin(number)
- returns the arcsine of a number
Note + returns a radian value, not a degree value...
atan(number)
- returns the arctangent of a number
Note + returns a radian value, not a degree value...
atan2(a,b)
- returns the angle from the x axis to a point
Note + returns a radian value, not a degree value...
ceil(number)
- returns a the nearest whole number greater than or equal to the number
Note + Opposite of Math.floor(number)
cos(number)
- returns the cosine of a number
Note + returns a radian value, not a degree value...
exp(number)
- returns the base of logarithms raised to a power
floor(number)
- returns the nearest whole number less than or equal to the number
log(number)
- returns the logarithm of a number
max(a,b)
- returns the number with the highest value of two numbers
min(a,b)
- returns the number with the lowest value of two numbers
pow(number, power)
- returns the value of a base expression taken to a specified power
random()
- returns a real number greater than or equal to 0, and less than 1.
Note + To make a whole number between a low and high value...
+ var random = lowvalue += Math.floor(Math.random() * (highvalue - lowvalue));
round(number)
- returns a number rounded to the nearest whole number
sin(number)
- returns the sine of a number
Note + returns a radian value, not a degree value...
sqrt(number)
- returns the square root of a number
Note + returns a radian value, not a degree value...
tan(number)
- returns the tangent of a number
Note + returns a radian value, not a degree value...
*** Array ***
// Array members
length
- returns number of elements in the array
Note + The length of an array is dynamic.
+ var drivers = new Array("opengl", "8bit", "grayscale") has a length of 3
concat(array)
- returns the array with the specified array concatenated onto it
Note + Simple example is... three = one.concat(two);
join()
- returns a string of all the elements of an array concatenated together
Note + This inserts a "," between all elements
reverse()
- returns the array reversed
slice(a,b)
- returns a specified part of the array, from array_object[a] to array_object[a + b]
Note + array_object(0,0) will return undefined...
sort()
- returns a sorted array
Note + A sort function can be passed as a parameter...
+ the sort function must take two values, a and b
+ the array is then sorted according the sort functions return values
+ If the return value is less than 0, the element a should be appear before element b...
+ If the return value is 0, then the two elements being compared should not be switched.
+ If the return value is greater than 0, the element b should be appear before element a...
+ example: array_object.sort(SortByNumber);
function SortByNumber(a,b){
return a - b;
}
+ If you want to sort alphabetically just use Array.sort() as it sorts alphabetically by default
push()
- returns the array with an item pushed onto the end of the array
pop()
- returns the array with an item removed from the end of the array
shift()
- returns the array with the first element at the beginning of the array, removed
unshift()
- returns the array with elements inserted at the beginnning of the array
splice(start_index, delete_count, new_elements)
- starting at start_index, this deletes delete_count elements and then inserts new_elements
- returns a section of the array
*** String ***
// members
length
- returns the length
+ e.g. var name = "bob";
+ name.length is 3
// methods
toNumber()
- returns a number value of the string
+ e.g. var fifty = "50";
+ fifty.toNumber() is 50
toUpperCase()
- returns a uppercase version of the string
+ e.g. var lower = "hello";
+ lower.toUpperCase() is "HELLO"
toLowerCase()
- returns a lowercase version of the string
+ e.g. var upper = "HELLO";
+ upper.toLowerCase() is "hello"
*** Number ***
// methods
toString()
- returns a string value of the number
+ e.g. var fourty = 40;
+ fourty.toString() is "40"
*** Boolean ***
// methods
toString()
- returns "true" or "false" depending on the boolean object
Thats its folks, soon, I will cover whatever anyone wants me to..
|