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

170
Views
How to add property name in JS via using push?

The below js snippet runs successfully. But if I try to not use any function; like addingTOobject_a used below; my program fails to run...

SUCCESSFUL SNIPPET ->

let a = [];

function addingTOobject_a(x, y){
    a.push({x, y});
}

console.log(a);

addingTOobject_a(["be", "happy"], false);
addingTOobject_a(["stay", "pretty"], true);
addingTOobject_a(["he", "is", "me"], false);

console.log(a);

UNSUCCESSFUL SNIPPET ->

let a = [];

a.push({x,y});

console.log(a);

a.push(["be", "happy"], false);
a.push(["stay", "pretty"], true);
a.push(["he", "is", "me"], false);

console.log(a);

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to define values for x and y somewhere.

If you aren't going to define x and y variables and then use them as shorthand properties in your object, then you need to define them at the same time as you define the object.

a.push({ 
    x: ["be", "happy"], 
    y: false
});
about 4 years ago · Juan Pablo Isaza Report
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!