将此PHP脚本转换为Javascript:
Area()
结果将是:
$ar = array();
// add dynamically new element to string array
$ar['aaa'] = "Hello";
$ar['bbb'] = "World";
$ar['ccc'] = "Test!";
foreach($ar as $key => $val){
print $key." => ".$val."\n";
}
谢谢!
答案 0 :(得分:1)
使用对象而不是数组:
const obj = {}
obj.aaa = "Hello"
obj.bbb = "World"
obj.ccc = "Test!"
for (const property in obj) {
console.log(`${property} => ${obj[property]}`)
}