Javascript Arrays
Every programming language has a mechanism to allow the programmer to create variables which hold custom data entered in by either the coder themselves or by the user of the application.
Regardless of whether you’re new to programming or not, you will have used variables and you should understand that in javascript they can hold any value such as a number or a string of text.
There is also another type of variable called an Array. Now, depending on who you talk to, some will say an array is actually an object, while others say it is a variable. Neither one is wrong but for the sake of simplicity we’ll refer to it as a variable.
Now, arrays are special because they can hold multiple values as opposed to standard variables which can only hold a single value at one time. If you can, try and imagine that your computer’s memory is made up of thousands of little boxes, and each of those boxes has an address which javascript will use to retrieve the array values when needed.
Take a look at the following code:
var myArray = new Array();
myArray[0] = “hi”;
myArray[1] = “there”;
myArray[2] = “Number”;
myArray[3] = “1”;
Let’s analyse the code above: On line one we use the var keyword to create our array. You will also notice on the same line we use the keyword new which tells javascript we’re creating a new object also.
The remaining lines pass the values ‘hi’,’there’,’number’,’1’, to each element in the array. One thing to keep in mind is that an array can have as many elements as needed, and although we are creating ours manually there are ways to pass values to an array more automatically by using looping structures but that is beyond the scope of this tutorial and will be saved for another day.
If you look a little closer at the code you will notice that the first element of our array starts with zero instead of one. In all programming languages array elements always start at zero and move upwards.
If you wanted to create an array with say three elements then you would count from 0 to 2, and likewise if you wanted to create an array with ten elements then you would count from 0 to 9. It is important to keep this in mind when you’re working with arrays that way you do not get errors when you try to iterate over them using loops or other methods to access each element.
Now if you want to access the values of each array element you would do something like the following:
document.write(myArray[0] + "
");
Obviously you would need to replace the number in the square brackets to access the value at that element. So for example if you had a three element array you could write the following:
document.write(mycars[0] + "
");
document.write(mycars[1] + "
");
document.write(mycars[2] + "
");
Arrays do take a little getting used to, but once you start using them you will wonder how you ever managed to get by without them.
other blog entries
Course Directory [training on all levels]
- .NET Classes
- Agile/Scrum Classes
- Ajax Classes
- Android and iPhone Programming Classes
- Blaze Advisor Classes
- C Programming Classes
- C# Programming Classes
- C++ Programming Classes
- Cisco Classes
- Cloud Classes
- CompTIA Classes
- Crystal Reports Classes
- Design Patterns Classes
- DevOps Classes
- Foundations of Web Design & Web Authoring Classes
- Git, Jira, Wicket, Gradle, Tableau Classes
- IBM Classes
- Java Programming Classes
- JBoss Administration Classes
- JUnit, TDD, CPTC, Web Penetration Classes
- Linux Unix Classes
- Machine Learning Classes
- Microsoft Classes
- Microsoft Development Classes
- Microsoft SQL Server Classes
- Microsoft Team Foundation Server Classes
- Microsoft Windows Server Classes
- Oracle, MySQL, Cassandra, Hadoop Database Classes
- Perl Programming Classes
- Python Programming Classes
- Ruby Programming Classes
- Security Classes
- SharePoint Classes
- SOA Classes
- Tcl, Awk, Bash, Shell Classes
- UML Classes
- VMWare Classes
- Web Development Classes
- Web Services Classes
- Weblogic Administration Classes
- XML Classes
did you know? HSG is one of the foremost training companies in the United States
Our courses focus on two areas: the most current and critical object-oriented and component based tools, technologies and languages; and the fundamentals of effective development methodology. Our programs are designed to deliver technology essentials while improving development staff productivity.
An experienced trainer and faculty member will identify the client's individual training requirements, then adapt and tailor the course appropriately. Our custom training solutions reduce time, risk and cost while keeping development teams motivated. The Hartmann Software Group's faculty consists of veteran software engineers, some of whom currently teach at several Colorado Universities. Our faculty's wealth of knowledge combined with their continued real world consulting experience enables us to produce more effective training programs to ensure our clients receive the highest quality and most relevant instruction available. Instruction is available at client locations or at various training facilities located in the metropolitan Denver area.
Upcoming Classes
consulting services we do what we know ... write software
The coaching program integrates our course instruction with hands on software development practices. By employing XP (Extreme Programming) techniques, we teach students as follows:
Configure and integrate the needed development tools
MOntitor each students progress and offer feedback, perspective and alternatives when needed.
Establish an Action plan to yield a set of deliverables in order to guarantee productive learning.
Establish an Commit to a deliverable time line.
Hold each student accountable to a standard that is comparable to that of an engineer/project manager with at least one year's experience in the field.
These coaching cycles typically last 2-4 weeks in duration.
Business Rule isolation and integration for large scale systems using Blaze Advisor
Develop Java, .NET, Perl, Python, TCL and C++ related technologies for Web, Telephony, Transactional i.e. financial and a variety of other considerations.
Windows and Unix/Linux System Administration.
Application Server Administration, in particular, Weblogic, Oracle and JBoss.
Desperate application communication by way of Web Services (SOAP & Restful), RMI, EJBs, Sockets, HTTP, FTP and a number of other protocols.
Graphics Rich application development work i.e. fat clients and/or Web Clients to include graphic design
Performance improvement through code rewrites, code interpreter enhancements, inline and native code compilations and system alterations.
Mentoring of IT and Business Teams for quick and guaranteed expertise transfer.
Architect both small and large software development systems to include: Data Dictionaries, UML Diagrams, Software & Systems Selections and more