6 Replies - 280 Views - Last Post: 13 March 2012 - 11:26 AM

#1 black_yurizan  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 80
  • Joined: 18-June 11

Can objects have arrays?

Posted 08 March 2012 - 06:41 AM

For example:


<script>
var fruitbasket = new Object();
fruitbasket.oranges= [];
fruitbasket.apples=[];
fruitbasket.lemons=[];
</script>




Another question, when you mention a property of an object do you have to mention the object and property together?
Like fruitbasket.lemons, or can you do it alone, like lemons[];.
Is This A Good Question/Topic? 0
  • +

Replies To: Can objects have arrays?

#2 tlhIn`toq  Icon User is offline

  • Closing in on 5,000
  • member icon

Reputation: 4926
  • View blog
  • Posts: 10,461
  • Joined: 02-June 10

Re: Can objects have arrays?

Posted 08 March 2012 - 08:40 AM

We learn so much more by actually doing than being handed the answers.

Might I suggest you actually code up a quick test and run it?

Experimentation... trial and error... These are by far the best teachers.

Give it a try at least.

This link should also be able to give you a lot of help on this very basic, intro stuff.
http://www.amazon.co...ords=javascript

or this one
http://www.google.co...=UTF-8&oe=UTF-8
Was This Post Helpful? 1
  • +
  • -

#3 JMRKER  Icon User is online

  • D.I.C Addict

Reputation: 115
  • View blog
  • Posts: 748
  • Joined: 25-October 08

Re: Can objects have arrays?

Posted 08 March 2012 - 01:05 PM

To help with your experimentation and reading assignments, try this:
<script type="text/javascript">
var fruitbasket = new Object();
fruitbasket.oranges= ['Mandrine','Navel','Florida','California'];
fruitbasket.apples=['Green','MacIntosh','Grannysmith'];
fruitbasket.lemons=['Large','Medium','Small','Extra Sour'];

alert(fruitbasket.oranges);
alert(fruitbasket.apples.reverse());
alert(fruitbasket.lemons[3]);
</script>



There are also other ways to make the assignments.

:online2long:
Was This Post Helpful? 2
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Closing in on 5,000
  • member icon

Reputation: 4926
  • View blog
  • Posts: 10,461
  • Joined: 02-June 10

Re: Can objects have arrays?

Posted 08 March 2012 - 01:34 PM

:offtopic:
Are they naval oranges because they help sailors not contract scurvy?
:boat:
Was This Post Helpful? 0
  • +
  • -

#5 Jstall  Icon User is offline

  • Lurker
  • member icon

Reputation: 434
  • View blog
  • Posts: 1,042
  • Joined: 08-March 09

Re: Can objects have arrays?

Posted 08 March 2012 - 03:17 PM

Well you made me curious, apparently no, they are named so because the blossom can resemble a human navel
Was This Post Helpful? 1
  • +
  • -

#6 JMRKER  Icon User is online

  • D.I.C Addict

Reputation: 115
  • View blog
  • Posts: 748
  • Joined: 25-October 08

Re: Can objects have arrays?

Posted 08 March 2012 - 06:51 PM

Q: What's the definition of a "Naval Destroyer"?

A: A hula-hoop with a nail in it!

:bananaman: :D
Was This Post Helpful? 0
  • +
  • -

#7 BobRodes  Icon User is offline

  • Your Friendly Local Curmudgeon
  • member icon

Reputation: 543
  • View blog
  • Posts: 2,896
  • Joined: 19-May 09

Re: Can objects have arrays?

Posted 13 March 2012 - 11:26 AM

tlhin, that's "Navel" not "naval". You got it backwards. :P
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1