how do I get the values inside an object in javascript

0

I have the following object, this content by a key KqTiAo1cC0nmASiGr941

in a normal object just say obj.rut and get the rut, but in this case the parent key -KqTiAo1cC0nmASiGr941 is present if I want to get the key I do it with Object.keys(obj) but how do I get its children values? , that only one variable remains with

{idLiqui: "-KqTiAkEtSrXZHoMo4I222",
 rut: "179888882",
status:"listo"}
    
asked by Luis Ruiz Figueroa 02.08.2017 в 23:24
source

2 answers

3

By being able to obtain the key of the main object "-KqTiAkEtSrXZHoMo4I222" with Object.keys(obj) .

You should be able to store the child object within a variable in the following way:

var obj_hijo = obj[Object.keys(obj)];

Once the content of the main object is stored in a variable, you should be able to easily call its content.

console.log(obj_hijo.rut);

I hope you have been useful.

    
answered by 03.08.2017 / 00:01
source
1

With abc being the variable of type Object , it would only be necessary to access through abc["-KqTiAkEtSrXZHoMo4I222"] .

var abc = {};
abc["-KqTiAkEtSrXZHoMo4I222"] = {idLiqui: "-KqTiAkEtSrXZHoMo4I222", rut: "179888882", status:"listo"};
console.log(abc);
var d = abc["-KqTiAkEtSrXZHoMo4I222"];
// Para obtener el valor del la propiedad rut
console.log(d.rut) // abc["-KqTiAkEtSrXZHoMo4I222"].rut
// 179888882
console.log(d.status) // abc["-KqTiAkEtSrXZHoMo4I222"].status
// listo
    
answered by 02.08.2017 в 23:50