In previous articles I described how to create Arrays, but if you forgot here is how you create arrays:
- var a = new array() // Creates an empty array
- var b = new array(8) // Creates an array with 8 element cells
- var c = [1, 2, "turtle", "number", true]; // Creates an array with a bunch of random values
- b.length // A property that would return the value of 8, because of the array declaration above
- c.concat(3,4) // The array c now has the values 1, 2, “turtle”, “number”, true, 3, 4
- c.join(“: “) // Returns a string with each element separated by a colon and a space. 1: 2: number: true
- c.slice(0, 2) // Returns an array which contains all elements between the first value you pass to the second value. In this example you would be returned [1, 2, number]
- c.sort() // Returns the array elements in alphabetical order. This example returns [1, 2, number, true, turtle]
- c.toString() // Converts the array into a string and then returns the string.
There are numerous date functions. I’ll cover the most commonly used here.
- a = new Date(); // Creates a new date object and assigns the current time to it
- document.write(a.getTime()); : Returns a millisecond representation of a date. ex. 1270487133410
- document.write(a.getDay()); : Returns the day of the week
- document.write(a.getFullYear()); : Returns the year of the date
- document.write(a.getHours()); : Returns the hours of the set date
- document.write(a.getMinutes()); : Returns the minutes of the set date
- a.setTime(); : Creates a millisecond representation of a date. ex. 1270487133410
- a.setDay(); : Sets the day of the week
- a.setFullYear(); : Sets the year of the date
- a.setHours(); : Sets the hours of the set date
- a.setMinutes(); : Sets the minutes of the set date
- isNaN(variableToTest) : Returns true if the variable is a number and false otherwise
- Math.abs(variableToTest) : Performs an absolute value calculation
- Math.ceil(variableToTest) : Rounds a number up
- Math.floor(variableToTest) : Rounds a number down
- Math.max(x, y) : Returns the larger of the two variables it is passed
- Math.min(x, y) : Returns the smaller of the two variables it is passed
- Math.random(): Returns a random number
- parseFloat(string) : Converts a string into a float number
- parseInt(string) : Converts a string into an int number
Here are a few of the most used string functions.
- stringVariable.length : Returns the number of characters in a string
- stringVariable.charAt(x) : Returns the character at the position sent to this function
- stringVariable.concat(x1, x2) : Adds one or more values to the end of the string
- stringVariable.indexOf(wordYourLookingFor, whereToStartSearch) : Searches the string for a chosen word or character
- stringVariable.replace(regexp, replacementText) : Search for a regular expression match and then replace the match with the replacement text given
- stringVariable.slice(startPoint, endPoint) : Extracts a string from the beginning point to the ending point given
- stringVariable.split(delimiter, maxLength) : Breaks a string into a series of cells, by separating the words by the chosen delimiter. ex. “1,2,3,4″.split(“,”) would return ["1","2","3","4"]. You have the option of defining a maximum number of elements in the array that is created.
- document.getElementsByName(idName) : Provides you with access to a node on the web page by passing it the id Name.
- document.write() : Appends text or variable values to the web page
- document.writeln() : Appends text or variable values to the web page, followed by a newline
- onclick : Performs an action when the user clicks on a node in a document
- ondblclick : Performs an action when the user double clicks on a node in a document
- onkeydown : Performs an action when the user presses a key
- onkeypress : Performs an action when the user presses and releases a key
- onkeyup : Performs an action when the user releases a key
- onmousedown : Performs an action when the user presses the mouse button
- onmousemove : Performs an action when the user moves the mouse
- onmouseout : Performs an action when the user moves the mouse off of an element
- onmouseover : Performs an action when the user moves their mouse over an element
- onmouseup : Performs an action when the user releases a mouse button
- node.appendChild(nodeName) : Inserts a new node after the node specified.
- node.insertBefore(nodeName) : Insert a new node in front of the node you specified.
- node.removeChild(nodeName) : Remove the child node of the node you specified
- node.replaceChild(nodeName) : Replace a child node with the new one you are specifying
As always, leave your questions or comments below.
Till next time…