how can i solve this exercise with array methods?

Solution 1:

Use the .map() array method as follows:

function nicknameMap(p) {
    return p.map(({name,age}) => `${name}-${age}`);
}
//output
//[
//  "ninny-19",
//  "albert-20",
//  "daniel-60",
//  "bob-20",
//  .....
//]

function nicknameMap(p) {
    return p.map(({name,age}) => `${name}-${age}`);
}

const p = [
  { name: 'ninny', age: 19},
  { name: 'albert', age: 20},
  { name: 'daniel', age: 60},
  { name: 'bob', age: 20},
  { name: 'wilfred', age: 40},
  { name: 'rob', age: 22},
  { name: 'gary', age: 9},
  { name: 'robin', age: 19},
  { name: 'carl', age: 43 },
  { name: 'v', age: 82 }
];

const nicknames = nicknameMap(p);
console.log(p);
console.log(nicknames);