1

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!!!!

asked Dec 18, 2015 at 23:37

1 Answer 1

1

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.

answered Dec 18, 2015 at 23:44

1 Comment

To spell it out a little more clearly, your book probably meant to say people[1].name; people[1].rate; and not person

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.