2016-10-10 95 views
0

我知道有很多解決方案可以從對象數組中獲取單個值。但我認爲必須有一種方法可以直接訪問這些值而不需要顯式的功能。從angularjs中的對象數組中獲取單個值

我有一個nodejs用戶的數組,我發送到前端並得到它result.data,但我只想在控制檯中打印所有用戶的objectName(s)。

[{"objectName":"cn=anna,ou=user,ou=system", 
"sn":["1"], 
"cn":["test1"], 
"objectClass":["top","inetOrgPerson","person","organizationalPerson"], 
"userPassword":["password"], 
"uid":["12345"]}, 

{"objectName":"cn=tim, ou=user,ou=system", 
"sn":["2"], 
"cn":["test2"], 
"objectClass":["top","inetOrgPerson","person","organizationalPerson"], 
"userPassword":["password"], 
"uid":["125342"]} 
] 

有沒有解決方法?有點像console.log(result.data.objectName) ..?

+0

沒有,如果你想訪問一個以上。沒有功能就無法完成 – charlietfl

回答

2

試試這個:

console.log(result.data.map(function(el){ return el.objectName }).toString());