简体   繁体   中英

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).

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 .

 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) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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