cómo obtener la longitud del objeto en javascript puro en este código
let myFavGames = { "Trinity Universe": { publisher: "NIS America", price: 40, }, "Titan Quest": { publisher: "THQ", bestThree: { one: "Immortal Throne", two: "Ragnarök", three: "Atlantis", }, price: 50, }, YS: { publisher: "Falcom", bestThree: { one: "Oath in Felghana", two: "Ark Of Napishtim", three: "origin", }, price: 40, }, }; // Code One => How To Get Object Length ? let objectLength = ?;Puede usar Object.keys() para obtener la cantidad de claves en su objeto:
const myFavGames = { "Trinity Universe": { publisher: "NIS America", price: 40, }, "Titan Quest": { publisher: "THQ", bestThree: { one: "Immortal Throne", two: "Ragnarök", three: "Atlantis", }, price: 50, }, YS: { publisher: "Falcom", bestThree: { one: "Oath in Felghana", two: "Ark Of Napishtim", three: "origin", }, price: 40, }, }; const objectLength = Object.keys(myFavGames).length; console.log(objectLength); // 3El método Object.keys() devuelve una matriz de nombres de propiedad enumerables propios de un objeto determinado.
console.log(Object.keys(myFavGames).length);