fab5freddy Posted December 14, 2010 Report Posted December 14, 2010 I am wondering how to filter results out of a record set. I have to find all of the "unique zip codes" in a record set and than display them. I have a start to the program where it displays all of the zip codes I'm just not sure how to filter out the duplicate so the don't show up. If I can do it as an array I think I know how to do it. I just need a little help in the right direction. Here is what I have so far. function project5Part1() { //Constant Variables ZERO = 0; // Variable Declarations var zipCode; var output; var records; var count = ZERO; var display = ""; // Display results output = document.getElementById("outputDiv"); // Open the Zip Code Study Records and make them // available to the script records = openZipCodeStudyRecordSet(); while (records.readNextRecord()) { zipCode = records.getSampleZipCode(); count++; } // Output the results output.innerHTML = display + "<br />"; } Quote
falkencreative Posted December 14, 2010 Report Posted December 14, 2010 Looks like searching Google for "javascript remove duplicates from array" should give you some useful results. Quote
fab5freddy Posted December 15, 2010 Author Report Posted December 15, 2010 I have went to many of the sites you told me about and have found great information. However I can not find out how to turn a recordset into an array. I know this is very basic, but it's just something I have missed. Here's my new code. /* This is the JavaScript code for "Find Unique Zip Codes" File: /unit5/project/project5Part1.html */ function project5Part1() { var myArray = new Array(); var sortedArrayOfStudents; var zipCodeRecords; var output; var arrayOfZipCodes; var test = ""; output = document.getElementById("outputDiv"); zipCodeRecords = openZipCodeStudyRecordSet(); while (zipCodeRecords.readNextRecord()) { arrayOfZipCodes = zipCodeRecords.getSampleZipCode(); myArray = arrayOfZipCodes; test += myArray + "<br />"; } output.innerHTML = test + "<br />"; //will have to fix output return false; } Quote
wjohn Posted December 15, 2010 Report Posted December 15, 2010 May I ask what the result is so far? Quote
fab5freddy Posted December 15, 2010 Author Report Posted December 15, 2010 So far my result is a list of over 900 zip codes. I have to find the duplicates and remove them, but am getting quite confused on this. Quote
wjohn Posted December 15, 2010 Report Posted December 15, 2010 I am not very experienced in JavaScript so bare with me If I'm out completely wrong, but as you put the next record in myArray that you later pass into the test variable before you do that check with a if-statement if the current myArray value contain in the test variable. if (check if (not)the current myArray value contain in the test variable) { test += myArray + "<br />"; } Quote
fab5freddy Posted December 20, 2010 Author Report Posted December 20, 2010 Thanks for checking out on the problem I have solved it. It was just a matter of missing a few things which happens from time to time Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.