I need to concate two key because i want to concate first and last name in one key username. Example array of json
arr = [
{id: 1 , first_name: Test , last_name: Test2 , city: "Berlin" } ,
{id: 2 , first_name: Alan, last_name: Test5 , city: "Minsk" } ,
]
I need create new object or same , to create anythink as
arr = [
{ id: 1 , first_name: Test , last_name: Test2 , city: "Berlin", username: "Test Test2" } ,
{ id: 1 , first_name: Alan, last_name: Test5 , city: "Berlin", username: "Alan Test5" } ,
]
idandcitysame on both on the output?TestandTest2andAlanandTest5some variables you have defined somewhere? Or should they be strings as wellreducemethod. For your code, I think this would work - arr.reduce((accumulator, currentValue) => { currentValue.username = `${currentValue.first_name} ${currentValue.last_name}; accumulator.push(currentValue); return accumulator; }, []); But as I can see first_name and last_name are not of string type. Please note that this will work only when first_name and last_name are of string type.