[Solved] If an array has an attribute, find the value of another attribute of the same array? [closed]


I think you need something like bellow. You have a JSON like bellow.

var data = {"dTableRowData": [
    {
        "id": "1",
        "rowData": [
            "tt",
            "Sep13, 2010"
        ],
        "action": [
            {
                "hrefvar": "aaa",
                "label": "fff"
            },
            {
                "hrefvar": "bbb",
                "label": "Details"
            },
            {
                "hrefvar": "ccc",
                "label": "View"
            }
        ]
    }
]}

You want to get an action for every object in dTableRowData. I added curly braces to dTableRowData other wise it will throw error.

So this is what worked for me using Javascript.

var actions = data.dTableRowData.map(function (obj) {
   // Get each object in data.dTableRowData and get action according to it's id from object
    return obj.action[obj.id];
});


console.log(actions);

1

solved If an array has an attribute, find the value of another attribute of the same array? [closed]