0

Please find attachment where Exact data I have. I want to read key name of Array. Like "CIRTGroupBox1", "CIRTGroupBox2", "CIRTGroupBox3"

Here I want to read key name of obj. Like "CIRTGroupBox1", "CIRTGroupBox2"

4

3 Answers 3

1

Try this :

var arr = [{
	'CIRTGroupBox1': ''
}, {
	'CIRTGroupBox2': ''
}, {
	'CIRTGroupBox3': ''
}];

// Using array.map() method
var usingMapKeys = arr.map((obj) => Object.keys(obj)[0]);

// Using Object.entries() method
var usingEnteriesKeys = arr.map((obj) => Object.entries(obj)[0][0]);

console.log(usingMapKeys);

console.log(usingEnteriesKeys);

Sign up to request clarification or add additional context in comments.

Comments

0

is it?

var x = {
 "ob1": "value",
 "ob2": {
 	"ob21": "value"
 }
};

var keys = Object.keys(x);

console.log(keys);

Comments

0

You can do that using Object.keys method in JS like below

var keys = Object.keys(groupBoxesTemp);

This will return string array and each item in it is the key of this object.

If you want to read values pertaining those 2 keys, you can do like below using the for-in loop:

 for(item in groupBoxesTemp){
     console.log('key is: ', item);
     console.log('value is: ', groupBoxesTemp[item]);         
}

Based on your screenshot, temp is an array of objects which has 3 objects in it. You can do that too like below:

temp.forEach(function(item, index){
    //key for all objects in the array will be logged.
    console.log( Object.keys(item) );
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.