Reputation: 29
In the fiddle - http://jsfiddle.net/vwwkf18c/ or below code snippet -
var a = [3, 4];
var b = [6, 2];
var c = $.extend({}, a, b);
alert(c[1]); //alerts 2
alert(a); //alerts array a contents
alert(c); //does not return contents of c
My questions - 1) After what has been alerted, we can infer that "c" is an object but not an array object. Please confirm. 2) Secondly it is said that internal representation of an array is an object literal, is that right? Which means that array "a" would be stored as given below -
var a = {
0: 3,
1: 4
}
Is it right? 3) How is a or b stored internally and how is it different from the internal representation of "c"?
Upvotes: 2
Views: 522
Reputation: 73
Check out this jsfiddle
var a = [3, 4];
var b = [6, 2];
var c = $.extend({}, a, b);
alert(c[1]); //alerts 2
alert(a); //alerts array a contents
alert(Object.getOwnPropertyNames(c)); //does not return contents of c
alert(Object.getOwnPropertyNames(a));
Hope that is helpful
Vikram
Upvotes: 0
Reputation: 944201
toString
method than the basic Object, which is why alert
gives different results.Upvotes: 1