array in recurssive function

Posted on 2014-10-15
Last Modified: 2014-10-17
I'm trying to modify a function and use an array.  It's a private function that seems to be in a closure.
The problem I'm having is that when _GetDataTable makes a call to itself, the array resets (understandable).
When I declare the array outside of the function, I get duplicate values of the same data.  Any ideas how to fix?

function _GetDataTable() //private function
		var retVal = "";
		var chkVal = "";

		colHeader = new Array();
		dataTableData = new Array();
		//base case:
		if(arguments.length == 1)
			var theCase;
			if( typeof arguments[0][0] == "string")
				if(arguments[0][1] && __MatchCase(arguments[0][1])) 
					if(arguments[0].length == 4)
					else if(arguments[0].length == 5) 

			else if((arguments[0].length == 4) || (arguments[0][2] && __MatchCase(arguments[0][2]))) 
			for(var i = 0; i < arguments.length; ++i)
						retVal += _GetDataTable(arguments[i]);		

		return retVal;

Open in new window

Question by:Isaac
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 82

Expert Comment

ID: 40383190
declare outside (yes you get duplicate)
after it's done remove duplicate from the array(s)

Author Comment

ID: 40383241
How would I remove the duplicates?
LVL 82

Accepted Solution

leakim971 earned 500 total points
ID: 40383250
var found = {};
var clean = [];
for(var i=0;i<myarray.length;i++) {
   var notfound = !found[ myarray[i] ];
   if(notfound) {
      found[myarray[i]] = true;

Open in new window


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
15 puzzle in Javascript/html 2 89
JS to redirect to prev page 8 47
Boolean 13 50
Scroll listener getting fired on initial page load 2 21
In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question