In this blog, I will explain how to use .map() functions in Angular.
We have an array containing multiple objects, each one representing an employee. You need to retrieve the id of each employee in an array object.
The callback runs for each value in an array and returns new value in the resulting array. The resulting array length will be the same as the original array.
We have an array containing multiple objects, each one representing an employee. You need to retrieve the id of each employee in an array object.
Input :- var employees = [ { id: 11, name: 'Ravishankar' }, { id: 12, name: 'Muthu' }, { id: 13, name: 'Mani' }, { id: 14, name: 'Ajith' } ]; Output :- [11, 12, 13, 14] var employeeIds = employees.map(employee => employee.id);
The callback runs for each value in an array and returns new value in the resulting array. The resulting array length will be the same as the original array.
Comments
Post a Comment