Here I want to read key name of obj. Like "CIRTGroupBox1", "CIRTGroupBox2"
Asked
Active
Viewed 58 times
0

Mit Jacob
- 159
- 1
- 15
-
Does `groupBoxesTemp.CIRTGroupBox1` do it? – ggorlen Nov 08 '19 at 16:55
-
[MDN: Working with objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects) – Andreas Nov 08 '19 at 16:55
-
That's not JSON, that's an object literal. [There's no such thing as a JSON Object](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/) – freefaller Nov 08 '19 at 16:56
-
[What is the difference between JSON and Object Literal Notation?](https://stackoverflow.com/questions/2904131/what-is-the-difference-between-json-and-object-literal-notation) – Andreas Nov 08 '19 at 16:57
3 Answers
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);

Debug Diva
- 26,058
- 13
- 70
- 123
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) );
});

Sagar Agrawal
- 639
- 1
- 7
- 17
0
is it?
var x = {
"ob1": "value",
"ob2": {
"ob21": "value"
}
};
var keys = Object.keys(x);
console.log(keys);

Bruno Fabricio Cassiamani
- 451
- 1
- 4
- 10