Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
508 views
in Technique[技术] by (71.8m points)

javascript - 如何使用javascript / jquery获取第一个json元素的json数组中所有键的值[重复](How can get the value of all the keys in json array at 1st json element using javascript/jquery [duplicate])

var resultJSON = [{"name":"AAA","createdDate":"8/14/2019"},{"name":"ABAB","_id":"52f0e7719c3fccfabfaaf5218bad7d22","createdDate":"8/14/2019"},{"name":"BBB","_id":"848e3d2fcedad749fa8dc22b97db663a","createdDate":"8/14/2019"}];

for (var k in resultJSON[0]);
alert(resultJSON[k]);
  ask by Ansh Jain translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use Object.keys() :(使用Object.keys() :)

var resultJSON = [{"name":"AAA","createdDate":"8/14/2019"},{"name":"ABAB","_id":"52f0e7719c3fccfabfaaf5218bad7d22","createdDate":"8/14/2019"},{"name":"BBB","_id":"848e3d2fcedad749fa8dc22b97db663a","createdDate":"8/14/2019"}]; console.log(Object.keys(resultJSON[0]));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...