I have a array of javascript objects
var arr = [
{
query_result_id: 25,
author_email: '[email protected]'
},
{
query_result_id: 28,
author_email: '[email protected]'
},
]
I am using .map to enter new values on each javascript object
arr
.map( s => s["status"] = "dev")
.map( s => s["customer_id"] = customerId)
.map( s => s["email_nb"] = emailId)
//and so on for about 10 new key/values
the output is:
var arr = [
{
query_result_id: 25,
author_email: '[email protected]',
status: dev,
customer_id: 45,
email_nb: 45
},
{
query_result_id: 28,
author_email: '[email protected]',
status: dev,
customer_id: 78,
email_nb: 56
},
]
Is it possible in javascript to not chain 10 .map but instead one single operation to make it cleaner and maybe even more performant/faster ?
arr = arr.map(s => { s.status = 'a'; s.customer_id = 'b'; return s; });