Use map
var output = data.map( s => ({letter:s.src}) );
Demo
var data = [{
"src": 'a'
},
{
'src': 'b'
},
{
'src': 'c'
}
];
console.log(data.map(s => ({
letter: s.src
})));
But if there are multiple other keys and you only want to change src
from it then
var output = data.map( s => {
if ( s.hasOwnProperty("src") )
{
s.letter = s.src;
delete s.src;
}
return s;
})
Demo
var data = [{
"src": 'a'
},
{
'src': 'b'
},
{
'src2': 'c'
}
];
var output = data.map(s => {
if (s.hasOwnProperty("src")) {
s.letter = s.src;
delete s.src;
}
return s;
})
console.log(output);