-2
var A=[];
var B={C:"",D:[]};
A.push(B);

Can someone explain what's the difference between A and B arrays?If possible a scheme to understand it better. Also i don't get why the code (B.C.length) gets as result the length of the first line instead of the number of the objects the C array contains.

mic4ael
  • 7,974
  • 3
  • 29
  • 42
user3014089
  • 13
  • 1
  • 1
  • 6
  • 3
    I feel like your question reflects a fundamental misunderstanding of the basics of javascript (A and B are not both arrays). Not only that, but I don't think you read the rules for what constitutes an appropriate question. I suggest searching up some basic tutorials on JavaScript on the site! – linstantnoodles Dec 07 '13 at 15:47
  • Well i am new to javascript.Can you point me some good tutorials? – user3014089 Dec 07 '13 at 15:53
  • 1
    Start with [this](http://eloquentjavascript.net/contents.html) – mic4ael Dec 07 '13 at 15:56
  • @mic4ael thank you.I will study and i will stop asking foolish questions. – user3014089 Dec 07 '13 at 16:00
  • It's not a foolish question. Just make sure you research the question yourself before asking for help. And that doesn't just apply to SO. – linstantnoodles Dec 07 '13 at 16:09
  • duplicate of [What is the difference between these arrays?](http://stackoverflow.com/q/9307085/218196) and [What is the difference between an array and an object?](http://stackoverflow.com/q/874205/218196). – Felix Kling Dec 07 '13 at 17:25
  • Stack Overflow is not the right place to learn a language from scratch. We expect that you already know the basics. – Felix Kling Dec 07 '13 at 17:26

1 Answers1

0
// this is an array
var a = [];  

// this is an object
var b = {};  

// this is an array of 2 objects
var c = [{}, {}];  

// this is an object with two properties, one of which is an array
var d = {x: [], y : "string"};  

// get number of elements in array
a.length;

// get length of string
d.y.length

// objects don't have length
b.length
Jim Cote
  • 1,746
  • 3
  • 15
  • 26