javascript array syntax

B

Bart Van der Donck

Giakko said:
is there a way to create an array in this way?:

new Array('key1'='value1','key2'='value2','key3'='value3')

This type of construction would not be an array anymore (though some
call it an associative array). The preferred term in javascript is an
object.

{ key1: 'value1', key2: 'value2', key3: 'value3' }
 
G

Gregor Kofler

Giakko meinte:
hello,
is there a way to create an array in this way?:

new Array('key1'='value1','key2'='value2','key3'='value3') ??????

JS doesn't know associative arrays. As Bart said - use an object instead.

Gregor
 
V

VK

Bart Van der Donck said the following on 11/30/2007 6:59 AM:
Giakko wrote:
This type of construction would not be an array anymore (though some
call it an associative array). The preferred term in javascript is an
object.
{ key1: 'value1', key2: 'value2', key3: 'value3' }

What you created is an Object, and I am not sure that is what the OP was
asking about. It reads as if it is being asked for a shortcut method to
doing this:

var myArray = new Array()
myArray['key1'] = 'value1';
myArray['key2'] = 'value2';
myArray['key3'] = 'value3';

myArray is still an Array, it is just overkill when a plain Object would
suffice. Even then, it is still an "Object", just an extended Object
with Array properties.

Date is also an extended Object with extra properties. The moment any
programmers gets the *difference* between an Object and an Array is
the moment one stops perling/phping around and starts programming.
Don't tell me you didn't reach this state, please.
 
T

Thomas 'PointedEars' Lahn

VK said:
var myArray = new Array()
myArray['key1'] = 'value1';
myArray['key2'] = 'value2';
myArray['key3'] = 'value3';

myArray is still an Array, it is just overkill when a plain Object would
suffice. Even then, it is still an "Object", just an extended Object
with Array properties.

Date is also an extended Object with extra properties.

Date is a *built-in* object that only *inherits from* Object.prototype
through the prototype chain.
The moment any programmers gets the *difference* between an Object and an
Array is the moment one stops perling/phping around and starts programming.
Don't tell me you didn't reach this state, please.

Google Groups knows that so far you never got any difference between
anything here (and the prospects for a change of that are equally bad),
so that point really is moot.


PointedEars
 
V

VK

VK said:
var myArray = new Array()
myArray['key1'] = 'value1';
myArray['key2'] = 'value2';
myArray['key3'] = 'value3';
myArray is still an Array, it is just overkill when a plain Object would
suffice. Even then, it is still an "Object", just an extended Object
with Array properties.
Date is also an extended Object with extra properties.

Date is a *built-in* object that only *inherits from* Object.prototype

So is String, Number, Boolean or Array or so on. Listen: you learn the
basics of OOP or stop posting. It's getting annoying.
 
T

Thomas 'PointedEars' Lahn

VK said:
VK said:
var myArray = new Array() myArray['key1'] = 'value1';
myArray['key2'] = 'value2'; myArray['key3'] = 'value3'; myArray is
still an Array, it is just overkill when a plain Object would
suffice. Even then, it is still an "Object", just an extended
Object with Array properties.
Date is also an extended Object with extra properties.
Date is a *built-in* object that only *inherits from* Object.prototype

So is String, Number, Boolean or Array or so on.

But `key1', `key2' and `key3' are _not_ properties that are *inherited* from
another (built-in) object, and newly created object is _not_ a *built-in*
object. That is the distinction you fail to make here.
Listen: you learn the basics of OOP or stop posting. It's getting
annoying.

ROTFL


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top