Week 15: Lab #29
Search Array of Objects
DUE: Thursday, 4/27 @ 5pm
Using
this array of objects holding movie information, create an input field to allow the user to search on multiple properties. Copy the entire contents of the file into your lab page within the script area.
The page must contain:
- A text input field to enter a search query.
- A drop-down menu listing properties that results will be sorted by.
- An empty div in which search results will be written to with the id "results".
The behavior of your script should be as follows:
- A change event should be added to the text input field to be triggered each time a key is pressed.
- When the change event occurs, loop over the array of films and compare all of the properties in the array of film object data using a single if statement connecting expressions with OR || operators.
- When a match is found, add a copy of the object instance into a new array of matches.
- At the end of the loop over all of the film data, sort the array of matches by the user selected property from the drop-down menu.
- After sorting the array of matches, output them to the "results" div by looping over the matches array.
- Make sure to nicely format the output so that each match is on its own line and the user is able to see all of the properties of the data.
Upload your completed lab by the due date specified above and make sure that you add a working link to it on your class page, otherwise it will not be reviewed and you will not receive credit.