HighDots Forums  

passing subarrays (by reference)?

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss passing subarrays (by reference)? in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
rootcho@gmail.com
 
Posts: n/a

Default passing subarrays (by reference)? - 01-28-2006 , 06:26 AM






hi,

let say i have the following array :

var ary = [
[ 'Directory', 'type', 'href', 'tip',
['file', 'type', 'href', 'filetip' ],
['file2', 'type2', 'href', 'filetip' ],
],
[ 'Dir2', 'href2', 'tipdir2' ]
]


I want to send to a function part of this array by reference.
Currently i tried to send whole array to function i.e.

myfunc(ary)

Then I want to walk the array like this :

function myfunc(a) {
for (el in a) { alert(el[0]) }
}

I expect to get in 'el' an array-reference not an index, so that I can
say el[0] instead ary[el][0].
I want this 'cause i will make a recursive function that will walk this
array, so it will be easy if i just pass a reference to subarrays not
indexes.

Do u have an idea how to do that ?

tia


Reply With Quote
  #2  
Old   
Randy Webb
 
Posts: n/a

Default Re: passing subarrays (by reference)? - 01-29-2006 , 07:40 AM






rootcho (AT) gmail (DOT) com said the following on 1/28/2006 6:26 AM:
Quote:
hi,

let say i have the following array :

var ary = [
[ 'Directory', 'type', 'href', 'tip',
['file', 'type', 'href', 'filetip' ],
['file2', 'type2', 'href', 'filetip' ],
],
[ 'Dir2', 'href2', 'tipdir2' ]
]


I want to send to a function part of this array by reference.
Currently i tried to send whole array to function i.e.

myfunc(ary)

Then I want to walk the array like this :

function myfunc(a) {
for (el in a) { alert(el[0]) }
}
alert(a[0])

Quote:
I expect to get in 'el' an array-reference not an index, so that I can
say el[0] instead ary[el][0].
el won't be an "array-reference". It never will. el will be a reference
to a property of the array. Slight but subtle difference, especially if
el refers to an array.

for (el in a){
if (typeof(a[el]) == 'Array')
{
subArrayRef = a[el];
}
}

Something to work with but not fool-proof. After the loop exits then
subArrayRef will point to the last entry of the array that is a sub-array.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.