Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

211
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!