Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
Create Proxy for accessing json object values using .value

Example Json

  let Settings = {    
      "Policy": {        
          "allowP": true,
          "allowC": false,            
      }
  }

How can i access get value using following syntax

console.log( Policy.allowP ); // should return true
console.log( Policy.value.allowP ); // should also return true 

i tried following using javascript proxy

 let  createProxy = (settings : any) => {
const p = new Proxy(settings, {
      get(target, p, _r) {
        debugger;
        if (p === "value") {
          return settings;
        }
        return (target as any)[p];

      },
    });
 return p;
 }

 let  getSettings = () => {
  var settings = Settings;
  const p = new Proxy(settings, {
      get(target, p, _r) {
        debugger;
        if (p === "value") {
          return  createProxy(settings);
        }
        return createProxy((target as any)[p]);

      },
    });
 return p;
};

Tried to create Nested proxy so that i can access values using key.value syntax.

Is this correct way to implement it ? or is there any better way ?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda