473,811 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What kind of data type is?

Hi everybody:

I'm new in Javascript, I found some code and there is this:

var fruit =
{
'apple' : { 'weight' : 10, 'cost' : 9},
'peach' : { 'weight' : 19, 'cost' : 10}
}

somebody can tell me what kind of data type is fruit??

Jul 23 '05 #1
13 2317
>>Hi everybody:
I'm new in Javascript, I found some code and there is this: var fruit =
{
'apple' : { 'weight' : 10, 'cost' : 9},
'peach' : { 'weight' : 19, 'cost' : 10}
}
somebody can tell me what kind of data type is fruit??


Hi gtux,

fruit is of type Object. More specifically, this is an object literal.
It's just another way of creating and initialize new objects.

The code that you see is creating a new Object with the properties
'apple', and 'peach'. In turn, 'apple' and 'peach, also have properties
'weight' and 'cost'.

Hope this clarifies.

Jul 23 '05 #2
gtux wrote:
var fruit =
{
'apple' : { 'weight' : 10, 'cost' : 9},
'peach' : { 'weight' : 19, 'cost' : 10}
}

somebody can tell me what kind of data type is fruit??


'fruit' is an object with two properties 'apple' and 'peach', themselves
objects with two properties each ('weight' and 'cost').

This construct "{/*...*/}" is called object literal (or object
initialiser), i.e an expression which creates an object and initialises
it at the same time. It is equivalent to:

var fruit=new Object(); // or var fruit={};
fruit.apple= { 'weight' : 10, 'cost' : 9};
fruit.peach= { 'weight' : 19, 'cost' : 10};

or

var fruit=new Object(); // or var fruit={};
fruit.apple=new Object(); // or fruit.apple={};
fruit.apple.wei ght=10;
fruit.apple.cos t=9;
//etc.

You can read more about the object literal in the ECMAScript
specification, §11.1.5.
HTH,
Yep.

Jul 23 '05 #3
VK


gtux wrote:
Hi everybody:

I'm new in Javascript, I found some code and there is this:

var fruit =
{
'apple' : { 'weight' : 10, 'cost' : 9},
'peach' : { 'weight' : 19, 'cost' : 10}
}

somebody can tell me what kind of data type is fruit??


Nested Hash table, aka Map table aka Associative array (choose what you
like).

Jul 23 '05 #4
VK said the following on 7/19/2005 6:31 PM:

gtux wrote:
Hi everybody:

I'm new in Javascript, I found some code and there is this:

var fruit =
{
'apple' : { 'weight' : 10, 'cost' : 9},
'peach' : { 'weight' : 19, 'cost' : 10}
}

somebody can tell me what kind of data type is fruit??

Nested Hash table, aka Map table aka Associative array (choose what you
like).


No, it is a plain Object and nothing more.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #5
Thanks a lot for yours respons

Jul 23 '05 #6
ASM
gtux wrote:
Hi everybody:

I'm new in Javascript, I found some code and there is this:

var fruit =
{
'apple' : { 'weight' : 10, 'cost' : 9},
'peach' : { 'weight' : 19, 'cost' : 10}
}


it is an object that could be assimilate to an array
(of fruits with a name, weight and cost)
copy+paste in a text editor the following
save in *.htm and open the file in a navigator :

<html><script type="text/javascript">
var fruit =
{
'apple' : { 'weight' : 10, 'cost' : 9},
'peach' : { 'weight' : 19, 'cost' : 10}
}

// one of traditionnal ways to set an array and sub-arrays
var vegetables = new Array('potatoes ','beans');
vegetables['potatoes'] = new Array('weight', 'cost');
vegetables['potatoes']['weight'] = 10;
vegetables['potatoes']['cost'] = 9;
vegetables['beans'] = new Array('weight', 'cost');
vegetables['beans']['weight'] = 19;
vegetables['beans']['cost'] = 10;

// results and exploitation :

document.write( '<p>apple : weight ='+fruit['apple']['weight']+
' - cost = '+fruit['apple']['cost'])

document.write( '<p>vegetables : weight =' +
vegetables['potatoes']['weight'] +
' - cost = '+vegetables['potatoes']['cost'])

var content='';
for(var foo in fruit) {
content += '<p>'+ foo + ' = ';
for(var truc in fruit[foo]) {
content += truc + ' : ' + fruit[foo][truc] + ' | ';
}
}
document.write( content);
</script></html>

--
Stephane Moriaux et son [moins] vieux Mac
Jul 23 '05 #7
VK
> >>var fruit =
{
'apple' : { 'weight' : 10, 'cost' : 9},
'peach' : { 'weight' : 19, 'cost' : 10}
}

somebody can tell me what kind of data type is fruit??

Nested Hash table, aka Map table aka Associative array (choose what you
like).


No, it is a plain Object and nothing more.


var objectObject = new Object();

This is the "plain Object" with only constructor and prototype in it.

You must meant to say that typeof(fruit) == 'object'. That's true but
it doesn't answer the OP question I quess: somebody can tell me what kind of data type is fruit?


Other words: how to call this particular data structure, how to refer
its internal data, using what methods.

This is a nested Hash table.
<http://www.geocities.c om/schools_ring/ArrayAndHash.ht ml#Hash_definit ion>

....
function fruit(fName,fWe ight,fCost) {
this.name = fName;
this.weight = fWeight;
this.cost = fCost;
}

var apple = new fruit('apple',1 0,9);
....

Something like above would be more casual instead of this "hash twist",
but it may appear more code effective if you create dozens and hundreds
of records at once.

Jul 23 '05 #8
VK wrote:
>var fruit =
>{
> 'apple' : { 'weight' : 10, 'cost' : 9},
> 'peach' : { 'weight' : 19, 'cost' : 10}
>}
>
>somebody can tell me what kind of data type is fruit??
Nested Hash table, aka Map table aka Associative array (choose what you
like).


No, it is a plain Object and nothing more.


var objectObject = new Object();

This is the "plain Object" with only constructor and prototype in it.

You must meant to say that typeof(fruit) == 'object'. That's true but
it doesn't answer the OP question I quess:
somebody can tell me what kind of data type is fruit?


Other words: how to call this particular data structure, how to refer
its internal data, using what methods.

This is a nested Hash table.
<http://www.geocities.c om/schools_ring/ArrayAndHash.ht ml#Hash_definit ion>

...
function fruit(fName,fWe ight,fCost) {
this.name = fName;
this.weight = fWeight;
this.cost = fCost;
}

var apple = new fruit('apple',1 0,9);
...

Something like above would be more casual instead of this "hash twist",
but it may appear more code effective if you create dozens and hundreds
of records at once.

What you're saying is that it's only an object because just about
everything's an object and since it looks like a hash, you can be more
specific and call it a hash.

I might agree if this 'hash' object had some functionality in line with
other hash implementations , but exceeded the base functionality of any
run-of-the-mill Object. But it doesn't.

The construct:
{ }

.... creates an object.

Fruit.prototype = {
weight: 0,
cost: 0
}

Is the prototype for a Fruit object a hash? Doesn't that mean that with
(x = new Fruit()), x is also a hash? But if that's true, aren't *all*
objects hashes?

No. Of course not.

They are objects. Objects that are so useful that you can use them much
like you would a hash. But you also use them like arrays. Or strings.
Or integers.

That does not make them hashes. Or arrays. Or strings. Or integers.

Objects are objects.

Jul 23 '05 #9
VK wrote:

gtux wrote:
var fruit =
{
'apple' : { 'weight' : 10, 'cost' : 9},
'peach' : { 'weight' : 19, 'cost' : 10}
}

Nested Hash table, aka Map table aka Associative array (choose what you
like).


Does that mean that Javascript calculates the hash value of a property
whenever you add it to an object?
And isn't each object a hashtable in that case?
Jul 23 '05 #10

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

Similar topics

6
2151
by: allyn44 | last post by:
HI--what I am trying to do is 2 things: 1. Open a form in either data entry mode or edit mode depending on what task the user is performing 2. Cancel events tied to fields on the form if I am in edit mode. The reason I want to do this is becasue when entering a new record the form is entered in data entry mode and I have lots of stuff happening upon entering and leaving fields. In edit mode I do not want the events to fire.
29
5912
by: A.P. Hofstede | last post by:
Could someone tell me where MS-Access (current and 97?) fit(s) on the RDBMS - ORDBMS - ODBMS spectrum? I gather it's relational, but how does it size up against/follow SQL2/3/4 definitions and how does it compare to other database vendors? Any articles that might be of interest? It's for an essay on database models... Thanks in advance, Alex
51
4574
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is there something wrong in there? -------------------------------------------------------------------- Types A type is a definition for a sequence of storage bits. It gives the meaning of the data stored in memory. If we say that the object a is an
5
1179
by: serge calderara | last post by:
Dear all, Does this datalist control is somehow similar as a datasource for any other control ? I really to catch the use of it, can we assimilate that control as a kind of dataset or dataprovider ? Similar things with the Repeater control is for defining a kind of section in a set of dta in a grid layout ?
16
10408
by: Abhishek | last post by:
why do I see that in most C programs, pointers in functions are accepted as: int func(int i,(void *)p) where p is a pointer or an address which is passed from the place where it is called. what do you mean by pointing to a void and why is it done? Aso, what happens when we typecast a pointer to another type. say for example int *i=(char *)p; under different situations? I am kind of confused..can anybody clear this confusion by clearly...
669
26278
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
5
1547
by: Jeff | last post by:
ASP.NET 2.0 This code crashes. It generate this error: Value cannot be null. Parameter name: type I've created some custom web.config settings and this crash is related to accessing theme custom settings. This code is where the crash occur: _instance = (DAL)Activator.CreateInstance(Type.GetType(min.test.Config.Settings.msgElement.ProviderType));
6
1669
by: jason | last post by:
Hello, I have a question about what kind of datastructure to use. I'm reading collumn based data in the form of: 10\t12\t9\t11\n 24\t11\t4\t10\n ..... I now have a structure which allows me to access the data like this: x->row.coll.value.d;
2
1804
klarae99
by: klarae99 | last post by:
Hello, I am working in Access 2003 to create a database to record information about an annual fundraiser. I was hoping someone could review my table structure and make sure that it is normalized correctly and that it is set up to do what I would like it to do. I have some doubts on my current table structure and I would really appreciate any suggestions for improvement before I move on to creating my data entery forms. The purpose of...
0
9730
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
10392
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
10403
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
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5555
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
5693
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4341
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.