как вернуть массив объектов с нужными полями объектов js (name, team,goals)
вот код
function getGoalsStat(players){
}
// examples
const players = [
{
name: 'Jason Mount',
birthdate: '19.12.1993',
country: 'Deutschland',
number: '21',
team: 'Manchester United',
position: 'MF',
goals: 4,
},
{
name: 'Jason Mount',
birthdate: '01.01.2001',
country: 'Deutschland',
number: '16',
team: 'Manchester United',
position: 'MF',
goals: 0,
},
{
name: 'Finne Bard',
birthdate: '13.02.1995',
country: 'Norwegen',
number: '26',
position: 'FW',
team: 'Fulham United',
goals: 1,
},
{
name: 'Gerhardt Yannick',
birthdate: '13.03.1994',
country: 'Deutschland',
number: 31,
position: 'MF',
team: 'Liverpool',
goals: 8,
},
];
console.log(getGoalsStat(players));
Ответы (1 шт):
Автор решения: vsemozhebuty
→ Ссылка
Судя по заголовку, вам нужно из одного массива объектов сделать другой с более ограниченным набором полей. Если я правильно понимаю, можно так:
function getGoalsStat(players){
return players.map(
({ name, team, goals }) => ({ name, team, goals })
);
}
// examples
const players = [
{
name: 'Jason Mount',
birthdate: '19.12.1993',
country: 'Deutschland',
number: '21',
team: 'Manchester United',
position: 'MF',
goals: 4,
},
{
name: 'Jason Mount',
birthdate: '01.01.2001',
country: 'Deutschland',
number: '16',
team: 'Manchester United',
position: 'MF',
goals: 0,
},
{
name: 'Finne Bard',
birthdate: '13.02.1995',
country: 'Norwegen',
number: '26',
position: 'FW',
team: 'Fulham United',
goals: 1,
},
{
name: 'Gerhardt Yannick',
birthdate: '13.03.1994',
country: 'Deutschland',
number: 31,
position: 'MF',
team: 'Liverpool',
goals: 8,
},
];
console.log(getGoalsStat(players));
Если нет, приведите пример желаемого результата.