如何在AngularJS中获取没有名称的数组元素值
How to get the array element value which has no name in AngularJS
在AngularJS控制器中,我有一个名为contact的关联数组。我需要得到这个没有名字的数组的元素。我在这里张贴了我的代码和回应,供您参考
这是我的控制器代码
function onSuccess(contacts) {
console.log(contacts);
for (var i = 0; i < contacts.length; i++) {
var list = contacts[i].phoneNumbers;
console.log(list);
}
}
this my contacts
array
[Contact, Contact, Contact, Contact, Contact, Contact, Contact, Contact]
0:Contact
addresses:null
birthday:Invalid Date
categories:null
displayName:"UIDAI"
emails:null
id:"16"
ims:null
name:Object
nickname:null
note:null
organizations:null
phoneNumbers:Array[1]
0:Object
id:"109"
pref:false
type:"other"
value:"1800-300-1947"
__proto_:Object
length:1
__proto_:Array[0]
photos:null
rawId:"17"
urls:null
__proto__:Object
1:Contact
addresses:null
birthday:Invalid Date
categories:null
displayName:"Distress Number"
emails:null
id:"17"
ims: null
name:Object
nickname: null
note:null
organizations:null
phoneNumbers:Array[1]
0:Object
length:1
__proto__:Array[0]
photos:null
rawId :"16"
urls:null
__proto__:Object
this my log of console.log(list) array
Array[8]
0:Array[1]
0:Object
id:"109"
pref:false
type:"other"
value:"1800-300-1947"
这里我要从这里得到元素value
这里phoneNumbers
是一个数组。
所以你需要以contacts[i].phoneNumbers[0].value
您还可以使用lodash实用程序从联系人数组中获取phonenumber列表。-Just For Info
list.value
会给你值
function onSuccess(contacts) {
console.log(contacts);
for (var i = 0; i < contacts.length; i++) {
if(contacts[i].phoneNumbers){
var list = contacts[i].phoneNumbers;
var value = list.value;
}
}
}
相关文章:
- 在函数中添加数组元素的数值
- 访问JSON对象内部的数组元素
- Mongoose-在更新中删除数组元素
- javascript数组元素是否知道其封闭数组
- 将数组元素附加到FormData dos'不适用于Firefox 15
- 如何在javascript中使用click函数选择数组元素
- 如何在JavaScript中剥离数组元素中的非整数
- 消隐数组元素是否生成自己的属性
- 如何使一个Math.random数组元素比另一个数组元素更有可能被选中
- 在Codrops的内容中添加数组元素展开缩略图网格预览
- if数组元素在for循环内部有条件
- 点击获取每个名称数组并隐藏每个元素
- 在一个对象的Javascript数组中,如果一个特定的数组元素本身就是一个对象数组,我如何通过名称/ID来定位该元素
- 我如何获得一个JS数组,它有一些元素也是数组,并使ALL数组元素成为顶级元素
- 访问名称中带点的数组元素
- 有没有一种方法来样式单独的数组元素在js
- 显示有延迟的数组元素
- 如何在AngularJS中获取没有名称的数组元素值
- 从 Javascript 中作为字符串接收的数组名称访问数组元素
- 如何选择名称数组中的所有元素