Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8737069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:26:03+00:00 2026-06-13T10:26:03+00:00

Possible Duplicate: How do I add a property to a Javascript Object using a

  • 0

Possible Duplicate:
How do I add a property to a Javascript Object using a variable as the name?
Dynamic property names for loop of object Javascript

In success of javascript function I receveing data and it look like this:

data.lvl1
data.lvl2
data.lvl3
...

let say I have only 3 elements in data and I would like to loop for each of them and rise alert for every level:

for(a = 1; a<= 3; a++)
{
   alert(data.lvl + a);
   //I would like to read lvl1, lvl2, lvl3
}

This approach is obviously wrong.
Please explain how to reach lvl1, lvl2 in loop when lvl number is based on increasing a.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:26:04+00:00Added an answer on June 13, 2026 at 10:26 am

    If you want to access a property name using a string, then use square bracket notation.

    foo.bar === foo['bar']
    

    Such:

    alert(data['lvl' + a]);
    

    But it would be better to restructure your data so that you had something like:

    data = { lvl: [1,2,3] }
    

    instead of

    data = { lvl1: 1, lvl2: 2, lvl3: 3 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Javascript expression to define object’s property name? I'm trying to add objects
Possible Duplicate: Detecting an undefined object property in JavaScript javascript undefined compare How we
Possible Duplicate: Dynamic loading of python modules python: How to add property to a
Possible Duplicate: How to add .php extension using .htaccess url rewriting? I want to
Possible Duplicate: How can I add resizable widgets in Qt Creator? I am using
Possible Duplicate: how do I add windows phone system colors to icon using expression
Possible Duplicate: Add a line to a file if it not exist using python
Possible Duplicate: default method argument with class property? I'm writing a recursive function and
Possible Duplicate: Can set any property of Python object In [67]: obj = object()
Possible Duplicate: Call to a member function on a non-object I try to call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.