I have an array of objects containing character information:
var characters = [
{ 'name': 'barney', 'age': 36, 'salary':{'amount': 10} },
{ 'name': 'fred', 'age': 40, 'salary':{'amount': 20} },
{ 'name': 'pebbles', 'age': 1, 'salary':{'amount': 30} }
];
My goal is to extract the salary amounts into a new array. I was able to achieve this by using two pluck
functions in sequence:
var salaries = _(characters)
.pluck('salary')
.pluck('amount')
.value();
console.log(salaries); //[10, 20, 30]
My question is, is there a way to accomplish this using only one pluck
function? Or perhaps there is a more efficient method utilizing a different lodash function?