JavaScript Get 1st Value in JSON?

How do I return the key (1st value) in each line  (Both ways as  JSON Array and  Standard) ?
	
	var botwts = [
	    {"1234567890" : true,
		"1234567891" : true,
		"1234567892" : true,
		"1234567893" : true}
	 
	]

///or 

	var botwts = [
	    {"1234567890" : true},
		{"1234567891" : true},
		{"1234567892" : true},
		{"1234567893" : true}
	 
	]
	
	
	for (var i = 0; i < botwts.length; i++) {

			console.log("==> Value from DL is : "+ botwts[i][0]);
	
	}

Open in new window

Want to only get the key returned for each line? Excuse me if my terminology is off. I still get confused as to what is what!
894359Asked:
Who is Participating?
 
leakim971PluritechnicianCommented:
	var botwts = [
	    {"1234567890" : true,
		"1234567891" : true,
		"1234567892" : true,
		"1234567893" : true}
	 
	];

for(var key in botwts[0])
    console.log("==> Value from DL is : " + key);

	var botwts = [
	    {"1234567890" : true},
		{"1234567891" : true},
		{"1234567892" : true},
		{"1234567893" : true}
	 
	];

for(var i=0;i<botwts.length;i++)
   for(key in  botwts[i])
        console.log("==> Value from DL is : " + key);

Open in new window

0
 
894359Author Commented:
Thank you~
1
 
Julian HansenCommented:
For the first example you can use Object.keys()
var keys = Object.keys(botwts[0]);
console.log(keys);

Open in new window

For the second you can use map()
var result = botwts.map(function(x) {
	return Object.keys(x)[0];
});	
console.log(result);

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.