0

i am new to this, so i will try to explain as good as i can.i have a object with array property like this:

.factory('NewOrderData', function () {
        var order = {

            personList: []
        };

    return order;
})

when i try to call the property with this function.

this.ageCalc = function (person) {


    var currentYear = person;

    return currentYear;
}

I get this on the browser: [{"firstname":"Paul", "birthday":"1990-01-01"}]

I want to access only birthday. I've tried to put a dot after person like this person.birthday , but then the field is just empty

Can sameone help?

2 Answers 2

1
[{"firstname":"Paul", "birthday":"1990-01-01"}]

...is an array with one element that is an object. So you need:

person[0].birthday

where person[0] gets the first (and only) element in the array, and then .birthday gets the birthday property of that element.

Sign up to request clarification or add additional context in comments.

Comments

0

As nnnnnn explained but to further clarify your doubt i want to explain working of object array

    var ob = [{a:1,b:2},{a:3,b:4}];

if i want to access the value of second object's b than i should write

    ob[1].b;

Comments

Your Answer

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.