Reputation: 4452
I have the below studentList
private studentList:Array<Student>
The Student class has a many properties and one of the property is 'status'. How can i set this 'status' property to a particular value for all the Students in the StudentList array.
I achieved this by doing forEach and setting it .
Is there a better way of doing this? May be avoid the iteration .
Upvotes: 0
Views: 42
Reputation: 276383
How can i set this 'status' property to a particular value for all the Students in the StudentList array.
Simple forEach would do it.
studentList.forEach(stu => stu.status = 'the value you want');
Upvotes: 1
Reputation: 5503
forEach is probably best for a status change. However, if it is an initial value, you are better embedded that as a default inside your Student class.
Upvotes: 0