473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

javascript array is not empty on creation

Hi,

im currently working on a web app which uses heavy javascript. in one
of the functions, a simple array is created using "var admin_types =
new Array();". This array is not empty, it has a length of 0 but
contains one element with the name "clone" and the value

function () { var copy = {}; for (var i in this) { var value = this[i];
try { if (value != null && typeof (value) == "object" && value !=
window && !value.nodeType) { value.clone = Object.clone; copy[i] =
value.clone(); } else { copy[i] = value; } } catch (e) { copy[i] =
value; } } return copy; }

why does this element get created?? The weird thing is that i use a lot
of arrays and this is the only one that has that element.

i tried this in firefox 1.0, ie 5.5 and mozilla 1.7.1 and the element
is in the array for all of them...
any help would be appreciated
Rusty

Jul 23 '05 #1
10 2007
i just discovered that all of the arrays in the web app have the
"clone" element. When i created a simple html page with a javascript
function in the head that creates an array, it does not contain a
"clone" element...

Jul 23 '05 #2
Lee
rusty said:

i just discovered that all of the arrays in the web app have the
"clone" element. When i created a simple html page with a javascript
function in the head that creates an array, it does not contain a
"clone" element...


It's not an element of the array, it's a method of the Array object.

Jul 23 '05 #3
if its a method, why can u access it using admin_types['clone'] ??

Jul 23 '05 #4
rusty wrote:
if its a method, why can u access it using admin_types['clone'] ??


admin_types['clone']

is the same as:

admin_types.clone

Have a look here:

<URL:http://www.faqts.com/knowledge_base/index.phtml/fid/144>
--
Rob
Jul 23 '05 #5
ok, thanks for the link, it helped a lot!

i found the spot where the clone method is added to the prototype of
Object, in a new library i recently included...

thanks for the help but i still don't understand why u can access a
method in the same way u can an element of an array??

Jul 23 '05 #6
ok, thanks for the link, it helped a lot!

i found the spot where the clone method is added to the prototype of
Object, in a new library i recently included...

thanks for the help but i still don't understand why u can access a
method in the same way u can an element of an array??

Jul 23 '05 #7
On 6 Dec 2004 21:02:44 -0800, rusty <ru***@barrett.com.au> wrote:
ok, thanks for the link, it helped a lot!

i found the spot where the clone method is added to the prototype of
Object, in a new library i recently included...

thanks for the help but i still don't understand why u can access a
method in the same way u can an element of an array??


object['property']

is called square bracket notation. It's a basic language component that
allows you to look up object properties using expressions. For example,
say that an object has a set of properties called prop1, prop2, ..., prop9
and you wanted to loop through all of them. Using square bracket notation,
you would write:

for(var i = 1; i <= 9; ++i) {
object['prop' + i]
}

On each iteration, the numbers 1-9 would be concatenated with the string
to produce the property name, which you could then query or modify.

This method of property look-up also applies to arrays, too, but arrays
treat numbers specially. If the string can be converted to a number, then
back to a string, and still match the original value exactly, it is
considered to be an array index, not a property. So:

'10' -> 10 -> '10' '10' array index
'05' -> 5 -> '5' '05' property name
'fg' -> NaN -> 'NaN' 'fg' property name

With objects, numbers are just property names, nothing more.

See <URL:http://www.jibbering.com/faq/faq_notes/square_brackets.html> for
a more detail description.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #8
Lee
rusty said:

ok, thanks for the link, it helped a lot!

i found the spot where the clone method is added to the prototype of
Object, in a new library i recently included...

thanks for the help but i still don't understand why u can access a
method in the same way u can an element of an array??


This is not "chat". Please follow standard capitalization standards
and spell words completely.

Jul 23 '05 #9
rusty wrote:
ok, thanks for the link, it helped a lot!

i found the spot where the clone method is added to the prototype of
Object, in a new library i recently included...

thanks for the help but i still don't understand why u can access a
method in the same way u can an element of an array??


You can:

<script type="text/javascript">
var o = {};
o.myMethod = function() { alert('hi'); }
o['myMethod']();

var myNewMethod = o['myMethod'];
myNewMethod();
</script>

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #10
thanx for the help, i took a look at that page and now understand
square bracket notation

Jul 23 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Charlene Russ | last post by:
Learn on-line at your own in a user-centered format with plenty of interaction and personal attention. This is a basic level coursed designed to introduce the novice to intermediate computer...
54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
6
by: ged | last post by:
Hi, i am a oo (c#) programmer, and have not used javascript for a while and i cant work out how javascript manages its references. Object References work for simple stuff, but once i have an...
5
by: JonH | last post by:
Ok, I have this dynamically created table in my one of my php forms that shows the names of the people the user has entered into a text field. When they hit add a row displays, showing the name...
1
by: akg250978 | last post by:
ok here is my problem i created the JS to insert rows in an html doc, this works perfectly but if i was to refresh the page or leave it and return to it L8 the rows have diappeared here is the...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
33
by: Zytan | last post by:
I want to make a zero element array. I know that Nothing is not the same as a zero element array, since I can't get the length of, or iterate through, an array = Nothing. I could make a zero...
2
by: joelkeepup | last post by:
Hi, I made a change this morning and now im getting an error that says either "a is undefined or null" or "e is undefined or null" the microsoft ajax line is below, I have no idea how to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.