这两个转换选项之间的Typescript有什么区别吗?
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
name = 'Angular';
userList: any = [{ "id": "001", "name": "mango" }, { "id": "002", "name": "apple" }, { "id": "003", "name": "banana" }, { "id": "004", "name": "pine" }, { "id": "005", "name": "orange" }, { "id": "006", "name": "chery" }, { "id": "007", "name": "watermelon" }, { "id": "008", "name": "grapes" }, { "id": "009", "name": "lemon" }];
userlist: any = [];
ngOnInit() {
for(let i=0; i<this.userList.length; i++) {
this.userlist.push(this.userList[i].name);
}
console.log(this.userlist);
}
OnClickUsername(username) {
console.log(this.userList.find(x => x.name === username));
}
}