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

212
Vistas
How do i add a property into an empty object?

I'm trying to create a function to add a new property with no value yet, into an empty object, but it keeps returning undefined

below is the code i've written

const obj1={};

function addData (object,prop1,value){
    object[prop1]=value;
};

console.log(addData(obj1,"Person 1",""))

i've tried writting this code outside the function and it works

obj1["Person 1"]="";
obj1["Person 2"]="";

it will return as below

{'Person 1' : '' , 'Person 2' : ''}

Why does the function return undefined whereas writing it manually works?

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