简体   繁体   English

如何获取在AngularJS中没有名称的数组元素值

[英]How to get the array element value which has no name in AngularJS

In AngularJS controller, I am having the associative array called contact. 在AngularJS控制器中,我有一个名为contact的关联数组。 I have to get the elements of the array which has no name. 我必须获取没有名称的数组的元素。 here I have posted my code and response for your reference 在这里,我已经发布了我的代码和回复,供您参考

this is my controller code 这是我的控制器代码

   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 这是我的contacts数组

[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 这是console.log(list)数组的日志

Array[8]
0:Array[1]
0:Object
id:"109"
pref:false
type:"other"
value:"1800-300-1947"

In here I have to get the element value from this. 在这里,我必须从中获取元素value

Here phoneNumbers is an array. 这里phoneNumbers是一个数组。

So you need to access it as contacts[i].phoneNumbers[0].value 因此,您需要以contacts[i].phoneNumbers[0].value身份对其进行访问

You can also use lodash utility to get list of phoneNumbers only from contacts array. 您也可以使用lodash实用程序仅从通讯录数组中获取电话号码列表。 -Just For Info -仅供参考

list.value will give you the value 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;
          }
        }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得具有分配了索引值的数组名称的输入元素? - How to get an input element that has an array name which I have assigned the value of the index? 如何使用 JavaScript 从具有相同名称但具有不同类型的数组中获取一个字符串/值? - how to get one string / value from an Array which has the same name but has a different type using JavaScript? 如何获取给定数组中具有最大长度的数组元素 - how to get the array element which has a maximum length in the given array AngularJS按名称/值选择数组哈希元素 - AngularJS select array hash element by name/value 如何组合具有相同属性值的数组中的元素 - How to combine element in array which has the same property value 按名称获取具有$ key的元素 - Get element by name which has $key AngularJS:通过字段名称获取数组值 - AngularJS: get array value by field name 从数组中获取Student的name元素具有最高分值,并在jquery中突出显示此名称 - Get Student's name element has highest point value from an array and highlight this name in jquery $ watch如何获取数组中已更改的值? - $watch how to get the which value has been changed in the array? 如何格式化名称具有特殊字符的数组(json 格式)中的元素? - How can I format an element in array (json format) which its name has special characters?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM