0

How can i access the property fm and lm which is inside an mobile array.

array=[
       {
        "name":"siddhesh",
        "mobile":[{"fm":"83******","lm":"78******"}]
       }
     ];
0

2 Answers 2

2

tl;dr array[0].mobile[0].fm

You can just use regular array and object accessors: - Having an array named arr = [], you can get any member of it by arr[index]. - Having an object named obj = {}, you can get any property of it by obj.propertyName.

Therefore:

// array
const a = array[0];
// object
const b = a.mobile;
// array
const c = b[0];
// object
const d = c.fm;
Sign up to request clarification or add additional context in comments.

Comments

0

In case if there's more than only one object inside your array, use following solution:

var array = [{"name":"siddhesh","mobile":[{"fm":"83******","lm":"78******"}]},{"name":"another","mobile":[{"fm":"23******","lm":"18******"}]}],
    res = [].concat(...array.map(v => v.mobile.map(Object.values)));

    console.log(res);

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.