SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
-
Sep 27, 2006, 23:51 #1
- Join Date
- Sep 2006
- Posts
- 40
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
to get array name that is passed to a java script function
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
-
Sep 28, 2006, 00:28 #2
- Join Date
- Oct 2004
- Location
- Sendai, Japan
- Posts
- 2,417
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Can you send the array name as part of the array? (Just an idea).
-
Sep 28, 2006, 01:26 #3
- Join Date
- Apr 2006
- Posts
- 802
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Sep 29, 2006, 01:40 #4
- Join Date
- Sep 2006
- Posts
- 40
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks
hi,
Thank u for ur ideas.
I prefer to pass the array name along with values.
-
Sep 29, 2006, 01:52 #5
- Join Date
- May 2003
- Location
- Cambridge, UK
- Posts
- 2,366
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
-
Sep 29, 2006, 02:31 #6
- Join Date
- Jun 2004
- Location
- Malmö, Sweden
- Posts
- 5
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
Sep 29, 2006, 03:09 #7
- Join Date
- Jan 2005
- Location
- Too far up north
- Posts
- 1,566
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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);
-
Sep 29, 2006, 15:48 #8
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
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="^$">
-
Sep 30, 2006, 01:17 #9
- Join Date
- Jan 2005
- Location
- Too far up north
- Posts
- 1,566
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Felgall, I didn't quite get to whom your answer was to.
Bookmarks