Q1) Find an employee with a Salary greater than 25000 in the array (Using find by id method).
Steps:
- Create an array of employee objects containing
id
,name
, andsalary
fields. - Use the
find()
method to locate the first employee whose salary exceeds 25000. - Print the result to the console.
Code:
Execution:
- Save the above code in a file named
findEmployee.js
. - Run the code using Node.js:
Expected Output:
Q2) Create an Angular application that prints the names of students who got 85% using filter and map methods.
Steps:
- Create a new Angular project.
- Generate a new component to handle the student data.
- Add an array of student objects with
name
andpercentage
fields in the component's.ts
file. - Use the
filter()
andmap()
methods to process the array and extract the names of students scoring 85% or more. - Display the filtered names in the component's
.html
file.
Commands and Code:
Create a new Angular project:
Generate a new component:
Modify the
student.component.ts
file:Modify the
student.component.html
file:Run the Angular application:
Access the application in a browser: Open http://localhost:4200 to view the results.
Expected Output:
On the webpage: