473,748 Members | 10,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

array.["property"]

Hi all,
what does it meaning that strange sintax (look at the object :) ?

if I have i.e. array.length I can use array.["length"] and is it
IE/Firefox compatible??

Nov 21 '06 #1
30 2944
Try it without the dot:

array['length'] is equivilant to array.length.

On Nov 21, 8:09 am, "josh" <xdevel2...@yah oo.comwrote:
Hi all,
what does it meaning that strange sintax (look at the object :) ?

if I have i.e. array.length I can use array.["length"] and is it
IE/Firefox compatible??
Nov 21 '06 #2
josh wrote:
Hi all,
what does it meaning that strange sintax (look at the object :) ?

if I have i.e. array.length I can use array.["length"] and is it
IE/Firefox compatible??
array["length"] is equivalent to array.length

In javascript, an object is the same as an associative array, which
makes the formal difference between arrays and objects blurry.

This is defined by the ECMA-262 standard, and is thus compatible with
all browsers and all javascript engines.

array.["length"] (mind the dot) is a syntax error. Some javascript
parsers *may* tolerate it but you *shouldn't* count on it.
--
Martijn Saly
Nov 21 '06 #3
Lee
josh said:
>
Hi all,
what does it meaning that strange sintax (look at the object :) ?
You seem to mean "look at the subject", and that's a nuisance with
some newsreaders. Don't ask people to read the subject while
they're reading the message.

>if I have i.e. array.length I can use array.["length"] and is it
IE/Firefox compatible??
No, you can't use that syntax in any browser, but you should be
able to use: array["length"] in any. There's no "dot".

You can use this notation to access attributes of any Object.
--

Nov 21 '06 #4

Martijn Saly ha scritto:

In javascript, an object is the same as an associative array, which
makes the formal difference between arrays and objects blurry.
please explain better what it mean 'makes the formal difference between
arrays and objects blurry'

Nov 21 '06 #5
josh wrote:
Martijn Saly ha scritto:

>In javascript, an object is the same as an associative array, which
makes the formal difference between arrays and objects blurry.

please explain better what it mean 'makes the formal difference between
arrays and objects blurry'
I mean to say that an object is so similar to an array that it becomes
difficult to explain what an object is compared to an array.

Consider an *object* with a length property. It can be accessed in two ways:

obj.length
obj["length"]

An *array* shows the same behavior, its second element can be accessed
in two ways:

array[1]
array.1
I would say the only difference is the way they are constructed. An
objects goes like one of these:

var obj = {foo: bar};
var obj = new Something(args) ;

but an array constructor producing an array with 2 elements goes like this:

var array = [foo, bar];
So you see, I can't really tell the functional difference between an
object and an array, other then the methods that come with an array.

--
Martijn Saly
Nov 21 '06 #6
Martijn Saly said the following on 11/21/2006 9:29 AM:
josh wrote:
>Hi all,
what does it meaning that strange sintax (look at the object :) ?

if I have i.e. array.length I can use array.["length"] and is it
IE/Firefox compatible??

array["length"] is equivalent to array.length

In javascript, an object is the same as an associative array, which
makes the formal difference between arrays and objects blurry.
NO! An Object in JS is *NOT* an associative array. JS doesn't have an
associative array - period.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 21 '06 #7
Martijn Saly said the following on 11/21/2006 10:21 AM:
josh wrote:
>Martijn Saly ha scritto:

>>In javascript, an object is the same as an associative array, which
makes the formal difference between arrays and objects blurry.

please explain better what it mean 'makes the formal difference between
arrays and objects blurry'

I mean to say that an object is so similar to an array that it becomes
difficult to explain what an object is compared to an array.

Consider an *object* with a length property. It can be accessed in two
ways:

obj.length
obj["length"]

An *array* shows the same behavior, its second element can be accessed
in two ways:

array[1]
array.1
I would say the only difference is the way they are constructed. An
objects goes like one of these:

var obj = {foo: bar};
var obj = new Something(args) ;

but an array constructor producing an array with 2 elements goes like this:

var array = [foo, bar];
Or like this:

var myArray = new Array(foo,bar)

or like this:

var myArray = new Array();
myArray[0] = foo
myArray[1] = bar

So you see, I can't really tell the functional difference between an
object and an array, other then the methods that come with an array.
You can give an Object a property called "length" and it can be unique
and meaningful to the programmer. That can not be said for an Array as
it has a very specific use of the length property.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 21 '06 #8

josh wrote:
Martijn Saly ha scritto:

In javascript, an object is the same as an associative array, which
makes the formal difference between arrays and objects blurry.

please explain better what it mean 'makes the formal difference between
arrays and objects blurry'
A javascript Array *is* an Object, it has a special length property (it
is self-adjusting and has a value that is always one higher than the
highest index) and a bunch of extra methods - push(), split(), pop(),
etc.

Javascript does not have "associativ e arrays". Its native Object uses
name:value pairs that make it similar to an associative array that can
be found in other languages, but it lacks features that might be
expected of an associative array.
--
Rob

Nov 21 '06 #9
Randy Webb wrote:
NO! An Object in JS is *NOT* an associative array. JS doesn't have an
associative array - period.
Must this continue to be said?

The fact is, there is no one definition for what an "associativ e array" is.
So how can you say that a js Object is not one?

Depending on how you choose to define an "associativ e array", an Object in
javascript can most certainly be described as one.

IMO, most programmers looking for an "associativ e array" in javascript are
in fact looking for what an Object offers. Despite its quirks and special
cases, I've never met or heard of a single person who was looking for an
associative array who was not satisfied using an Object.

I propose:

<FAQENTRY>

Q: How do I implement an Associative Array in Javascript?

A: The term Associative Array is vague, having different meanings in
different languages, so it's impossible to know what behavior is expected of
an Associative Array implementation. However, Javascript's Object() can
behave as a key/value storage object, which is the minimum that most people
expect from an Associative Array implementation.

A simple example:

var assocArray = {};
assocArray["key"] = "value";
alert(assocArra y["key"]);
for (var key in assocArray) {
alert(key + " = " + assocArray[key]);
}

Using a Javascript Object() as an Associative Array comes with the following
limitations:
1. Keys must be strings, not arbitrary objects.
2. Some keys are invalid, because Javascript's Object has built-in
properties that cannot be over-written.
3. Some keys will exist by default because of Object's built-in properties.
These will not be enumerated in for..in loops but can be directly accessed.
4. No method or property exists by default to retrieve the size - or number
of keys - currently stored.

</FAQENTRY>

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Nov 21 '06 #10

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

Similar topics

3
1677
by: Gary | last post by:
Hi, In the program below, C = A+B, and the aim is to delay the calculation of C until the user asks for C. The boolean mUTD (UpToDate) is used indicate when Calc() must be run to make the C = A+B calculation before C is returned to user. When the Driver program at bottom is run, the behavior is very strange, the debug statement "in Calc" gets printed several times on entry to the constructor, and then again several times when T.A = 1...
8
14274
by: Don Wash | last post by:
Hi There! I'm using VB.NET to create a TreeView application and unfortunately I could not find "Key" property in Node items of the TreeView. We used to have "Key" property in TreeView node object in VB6. What is the equivalent of "Key" property of TreeView node in VB.NET? Has the property name "Key" has been changed to something else? Or VB.NET does not support the "Key" property anymore? If so what are the alternatives?
3
2266
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte() on WebForm1.aspx, I use "Public Property" and I declare variable _oRpte as Friend Shared. That's my problem. If I don't declare _oRpte as Friend Shared, I can't use WebForm1.oRpte() on other webpage. If I declare _oRpte as Friend Shared, I can use...
7
8628
by: =?Utf-8?B?YXVsZGg=?= | last post by:
hello, i'm try to research the way to open a remote machine's to collect the services and processes. i have the local data collection running but i can not figure out what MSDN or the C# help file is stating how to use "servicecollecter.machinename" to get the remote server's data. there is no samples on using framework to do this but loads of WMI. can someone share any sample / snippet on using framework with C# 2005 to get the...
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9541
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4602
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.