此问题已在此处有答案:
From an array of objects, extract value of a property as array(25个回答)
两年前关闭。
0: {id: "7B5B201E-35AA-48A1-B919-002445319F8B", name: "Naman Sabarwal"}
1: {id: "EA6672BA-4F7A-4214-A37F-00716CE698C9", name: "me name"}
2: {id: "01F29920-9206-42DF-8151-00A6A080C501", name: "Nitesh Negi"}
I want to get a list such that the list contains only the name key values.
listOfNames = ['sonu singh','me name','harman jain']
How to get all the values of the key 'name'?
3条答案
按热度按时间csga3l581#
wztqucjr2#
你可以尝试如下。
tgabmvqs3#
如果是json对象,如details = [{id:“",name:“"},{id:“",name:“"},{id:“",name:“"}]
你可以使用map函数
要缩短此代码,请输入names =values.map(value=〉returnvalue.name)