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

133
Views
how to reference an object from dynamic string

given the code below, is there any way i can push objects into an array using a loop that builds the object name dynamically?

I mean, push objects plant 1 to plant 5 into the array using a loop. Right now, the code just push the string into the array.. and i want to reference the existing object..

I would much appreciate any help.

function Plants( name , price, type) {
   name;
   price;
   type;
}

const plant1 = new Plants ("Monstera Deliciosa", 4500, "interior");
const plant2 = new Plants ("Monstera Adansonii", 1800, "interior");
const plant3 = new Plants ("Sanseviera", 800, "interior");
const plant4 = new Plants ("Pilea", 2000, "interior");
const plant5 = new Plants ("Euphorbia", 2500, "interior");

const plantsCatalog = []

    for (i = 1; i<=5; i++){
        let objplant = `plant${i}`
    plantsCatalog.push(objplant)
    
    console.log(objplant)
  }


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!