简体   繁体   English

Javascript:显示数组中键的值

[英]Javascript : Display value of key from array

I have this array "Group": 我有这个数组“组”:

在此处输入图片说明

i would like to have the value of name (test01) but i have undefined with console.log(group['name']), console.log(group[name]) or console.log(group.name). 我想使用名称(test01)的值,但使用console.log(group ['name']),console.log(group [name])或console.log(group.name)时未定义。

How i can display the value ? 我如何显示值?

Thanks 谢谢

It's an array of objects - access the specific object first using group[0] then access the property you want with group[0].name . 它是一个对象数组-首先使用group[0]访问特定对象,然后使用group[0].name访问所需的属性。

 const group = [{ name: "test01" }]; const res = group[0].name; console.log(res); 

Based on what you have you can call your propriety if it's an object or an array of objects. 根据您拥有的东西,如果它是一个对象或对象数组,则可以称为“专有性”。

 const object = { name: "test1", group: "c2" } console.log(object.name) const array = [{ name: "test1", group: "c2" }] console.log(array[0].name) 

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM