有没有人能够提示我如何使用forEach方法迭代货币数组以获取对象的ID和名称。
const currencies = [{
id: 'USD', name: 'US Dollars'
}, {
id: 'UGX', name: 'Ugandan Shillings'
}, {
id: 'KES', name: 'Kenyan Shillings'
}, {
id: 'GHS', name: 'Ghanian Cedi'
}, {
id: 'ZAR', name: 'South African Rand'
}];
var populateCurrencies = (currencies)=>{
currencies.forEach(function(id,name){
}
}
obj.x
,obj.y
更改为obj.id
和obj.name
。在这种情况下,您可以接受重复。 - adiga