-1

this is my code javascript i do not know where the problem is ? it is just displaying first name ?

// 
let people = [{
    first_name: "Riche",
    last_name: "Aboubaker"
},
{
    first_name: 'KADD',
    last_name: 'Missinsn'
},
{
    first_name: 'laala',
    last_name: 'Jason'
},
]

// create new array with the string full name of each person

let fullNames = people.map((person) => {
    return person.first_name , person.last_name ;
});
console.log(fullNames);
TRicheT
  • 1
  • 1
  • 1
    What do you expect the comma to do? You need to concatenate the strings. – Phix Nov 16 '21 at 21:11
  • See [What does this symbol mean in JavaScript?](/q/9549780/4642212) and the documentation on MDN about [expressions and operators](//developer.mozilla.org/docs/Web/JavaScript/Reference/Operators) and [statements](//developer.mozilla.org/docs/Web/JavaScript/Reference/Statements). – Sebastian Simon Nov 16 '21 at 21:14
  • thank you for your reply Phix – TRicheT Nov 16 '21 at 21:16
  • In one line using template literals with destructuring `first_name,last_name` `people.map(({first_name,last_name}) =>``${first_name} ${last_name}``)` gives result as ` [ "Riche Aboubaker", "KADD Missinsn", "laala Jason" ]` – XMehdi01 Nov 16 '21 at 21:20

1 Answers1

1

The comma does not concatenate the strings. Use the +operator for this. Also don't forget to add a space in between.

let people = [{
    first_name: "Riche",
    last_name: "Aboubaker"
},
{
    first_name: 'KADD',
    last_name: 'Missinsn'
},
{
    first_name: 'laala',
    last_name: 'Jason'
},
]

// create new array with the string full name of each person

let fullNames = people.map((person) => {
    return person.first_name + ' ' + person.last_name ;
});
console.log(fullNames);
Anton Thomas
  • 121
  • 1
  • 6