FSD-II (Student_angular)Slip
Create Angular 13application that print the name of students who got 85% using filter and map method.
app.component.ts
import { Component, OnInit } from '@angular/core';
interface Student {
name: string;
percentage: number;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
students: Student[] = [
{ name: 'Ram', percentage: 90 },
{ name: 'Sunil', percentage: 85 },
{ name: 'Suresh', percentage: 82 },
{ name: 'Mona', percentage: 85 },
{ name: 'Sona', percentage: 78 },
];
studentsWith85: string[] = [];
ngOnInit(): void {
this.studentsWith85 = this.students
// filter those whose percentage is exactly 85
.filter(s => s.percentage === 85)
// then map to just the names
.map(s => s.name);
}
}
app.component.html
Comments
Post a Comment