avatar
extract values from array of objects Javascript

• Based on query data using Eloquent in Laravel models or retrieving data from RESTful APIs, we have the following JSON string:

const obj = [
    {
        "course_id": 1,
        "instruction_id": 131,
        "instruction": {
            "id": 131,
            "title": "Laravel Dashboard With VueJs Framework"
        }
    },
    {
        "course_id": 1,
        "instruction_id": 134,
        "instruction": {
            "id": 134,
            "title": "Test 2"
        }
    },
    {
        "course_id": 1,
        "instruction_id": 132,
        "instruction": {
            "id": 132,
            "title": "Setup Hosting Provider and Domain Settings"
        }
    }
];

• Use the map function to extract title values.

const titleEnArray = obj.map(item => item.instruction.title);

Here is output:

[
    "Laravel Dashboard With VueJs Framework",
    "Test 2",
    "Setup Hosting Provider and Domain Settings"
]
You need to login to do this manipulation!