Skip to main content

Posts

Showing posts from November, 2019

How To Use .map() In Angular

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. 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.

How To Use .filter() In Angular

In this blog, I will explain how to use .filter() function in Angular. We have an array containing multiple objects, each one representing an employee, but only want some of the objects in it. That’s where .filter() comes in. var employees = [ { "id": 1, "name": "Nikhil", "role": "Developer" }, { "id": 2, "name": "Nikunj", "role": "Tester" }, { "id": 3, "name": "Dharmesh", "role": "Tester" }, { "id": 4, "name": "Mikin", "role": "Developer" } ] So we want two arrays, one for employee a role is a Developer and another one is for Tester. You can achieve this using .filter(). var developers = employees.filter(employee => employee.role == "Developer"); var Testers =