I am assuming this is javascript (based on the question's tag). In which case the code you are trying to execute seems wrong.
Solution to Question
var list = [{firstName: "James", lastName: "M.", age: 58}, {firstName: "Rachel", lastName: "W.", age: 51}];
list.forEach((entry) => {
entry.fullName = entry.firstName + " " + entry.lastName;
});
console.log(list[0].fullName);
In this solution, I am simply looping through all the elements of the array and assigning a new property "fullName" with the values of the element's own property.
There are multiple ways to do it, this is just the most simplest way to clear your understanding.
To display the individual property
console.log(list[0].firstName);
Note, the array index accessor is after the array name list and not after the attribute/property name firstName in this case.
Also in your provided code there is no attribute firstName so do have some checks in place else it will use undefined value and might throw some error depending on your development environment.
Computed Attribute (getter accessor)
You should also think about how the array data will behave if the value of the attributes/properties changes.
For example if you change the firstName attribute/property then you need to remember to update the fullName attribute/property as well, else they will be out of sync.
The more efficient way to do this task is to have the attribute/property as a computed attribute/property (think functions or more accurately getters)
Sample Code
var list = [{
firstName: "James",
lastName: "M.",
age: 58,
get fullName() {
return this.firstName + " " + this.lastName;
},
}, {
firstName: "Rachel",
lastName: "W.",
age: 51,
get fullName() {
return this.firstName + " " + this.lastName;
},
}];
console.log(list[0].fullName);
You can learn more about getters as well as setters at JavaScript Accessors (Getters and Setters)
list.firstNameorlist.firstName[0]do not exist,list[0].firstNamedoes, but you don't need any of them.itm.username = itm.firstName + itm.lastName;is what you are looking for.