hi all,
I want to get the name of the array(not elements) that is passed to a function.
So i can do operations based on the array name.
Thank U
| SitePoint Sponsor |
hi all,
I want to get the name of the array(not elements) that is passed to a function.
So i can do operations based on the array name.
Thank U
Can you send the array name as part of the array? (Just an idea).




An Array doesn't have a name. The variable you think of as the Array's name is just a transient handle that points to the Array. It isn't a string, it's string value is the string value of the Array.
If you need a string, make the Array a property of some object and use the property name.
hi,
Thank u for ur ideas.
I prefer to pass the array name along with values.





Arrays don't have names, as mrhoo said, so you can't 'pass the array name'. You can call it whatever you want in the function that you are passing it to.
You should look into using JSON instead then ... then you can have a name for your object and each of the values inside it ... like this
function myFunc( jsonobject ){
myObject = eval ( jsonobject )
alert( myObject.name )
}
www.json.org





Why the use of eval?
Simply pass an Object with 2 properties, name and data (or whatever you wanna call it)
Code:function myFunction(oMyObject) { alert(oMyObject.name); // animalObject alert(oMyObject.name + " has " + oMyObject.data.length + " animals"); } var oMyAnimalObject = { name: "animalObject", data: [ "dog", "cat", "horse", "pig", "bird" ] }; myFunction(oMyAnimalObject);

That is a perfectly valid Javascript notation that predates its being borrowsd for use with JSON.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">





Felgall, I didn't quite get to whom your answer was to.
Bookmarks