Problems with JavaScript to show the values of an object

0

In the following example you can find a Json with previously established information. The problem is that the identifiers are numeric. How can I extract the textual information?

Example Hola mundo .

var col =  [];
var mydata = 
[{
  "01:23:2018, 10:02:32" : "Hola",
  "01:23:2018, 10:02:38" : "Mundo",
  "01:23:2018, 10:02:40" : "Somo tu y yo",
   "username" : "Juan"
				    },];   
                
                 
                 
             for (var i = 0; i < mydata.length; i++) {
                      for (var key in mydata[i]) {
                          col.push(key);
                            }
                            }
                            
                        console.log(col)
    
asked by Juan David Peña Melo 28.01.2018 в 17:21
source

1 answer

1

mydata is an array that has as its first and only member an object with several properties. To extract a point data, that is, the value of a property, among other alternatives, you can use a double "key" in the following way:

mydata[0]["01:23:2018, 10:02:32"]

The following example prints the value of the previous statement to the console:

var col = [];
var mydata = [{
  "01:23:2018, 10:02:32": "Hola",
  "01:23:2018, 10:02:38": "Mundo",
  "01:23:2018, 10:02:40": "Somo tu y yo",
  "username": "Juan"
}, ];

console.info(mydata[0]["01:23:2018, 10:02:32"])

To print all the values, one way to adapt the code of the question is as follows:

var col = [];
var mydata = [{
  "01:23:2018, 10:02:32": "Hola",
  "01:23:2018, 10:02:38": "Mundo",
  "01:23:2018, 10:02:40": "Somo tu y yo",
  "username": "Juan"
}, ];



for (var i = 0; i < mydata.length; i++) {
  for (var key in mydata[i]) {
    //col.push(key);
    console.info(mydata[0][key])
  }
}

References

answered by 28.01.2018 / 19:32
source