Performing complex operations
To tackle an array of objects, we have to handle them in an iterative method. We will have to come up with an iterative solution in which we target one object at a time; once the object is accessed, we would not target that object another time. This allows us to maintain data integrity as we can avoid accessing the same object multiple times, thereby avoiding any redundancies. The looping statements in JavaScript are the while
loop and the for
loop. Let us take a quick look at how we can use these looping techniques to traverse through our employees' array.
In the while_employees_traversal.html
file, we are importing the data.js
file, which we had examined in the previous section. The data_json
variable inside the data.js
file consists of an array of objects that are imported into this HTML page. In the script
tags, we are setting up two variables: the i
variable to hold a starting counter and the employeeCount
variable to hold the counter of the total number...