Reputation: 43
I have a specific question. I was studying from my JavaScript book. It gives an example of an array object. I am questioning how my book says to call it.
var people = [
{ name: 'Casey', rate: 70, active: true},
{ name: 'John', rate: 130, active: true},
{ name: 'Jodie', rate: 125, active: false},
{ name: 'Bettie', rate: 80, active: true}
]
They say to call it like:
person[1].name;
person[1].rate;
Which would return:
John 130
My question is: Isn't there a step missing? How does JavaScript know that person[] is supposed to be an array of people[]? Did the textbook fail to say that a person[] array needs to be declared for people[]? Am I missing something? How does person[] get connected to people[]? Does it intuitively know? Yes, I'm a newbie. Should there be a declaration as follows:
var person[] = people[];
I know that looks bad, but how does person get anything from people when person was never declared? Thanks!!!!
Upvotes: 1
Views: 27
Reputation: 51
There is either a step missing here or there's a chance it could be a typo in the book. But your intuition is correct. JavaScript has no sense of the English language so it does not know that a group of persons may be referred to as people.
Upvotes: 1