Filter object key by on comparing values under different keys

I would like to filter results such that when I compare the value under Score with the value under against, I return the winning team

Using this as an example

const newData = [
    {"Year": 1,
    "Score": 3,
    "Against": 5,
    "GameID": 2,
    "Team": 'A' },
    {"Year": 1,
    "Score": 5,
    "Against": 3,
    "GameID": 2,
    "Team": 'B' }
]

My desired output would be ['B']

This is what I have tried

const newArr = newData.filter(element => element.Score > element.Against)
console.log(newArr.Team)

This returns undefined


Solution 1:

newArr is an array, and the property Team does not relate to it, but to its elements. You can use map to convert the array of objects to an array of team name(s):

const newData = [{"Year": 1,"Score": 3,"Against": 5,"GameID": 2,"Team": 'A'},{"Year": 1,"Score": 5,"Against": 3,"GameID": 2,"Team": 'B'}]

const newArr = newData.filter(element => element.Score > element.Against)
                      .map(element => element.Team);
console.log(newArr)