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 3346176
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:16:21+00:00 2026-05-18T01:16:21+00:00

If I have a string of myArray[0].myPrice , how do I turn this in

  • 0

If I have a string of "myArray[0].myPrice", how do I turn this in to a reference to myPrice?

This is the code context:

binding.value = convert(binding.data[binding.field], 
                        binding.converter, binding.data, elem); 

binding.field is what contains “myArray[0].myPrice”.

binding.data has a reference to the hierarchical object which has an Array property of myArray, and the first element is an object with a property of myPrice.

EDIT: based on the answers, this worked:

binding.value = convert(eval('(binding.data.' + binding.field + ')'), 
              binding.converter, binding.data, elem);

Is it good to use eval like this? I thought eval was going away in newer JavaScript?

  • 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-05-18T01:16:22+00:00Added an answer on May 18, 2026 at 1:16 am

    You can use eval, but here is a better solution:

    // The following code results in the same as that scary eval(...)
    
    var data = binding.data,
        chain = binding.field.split(/[\.\[\]]+/);
    
    for (var i = 0; data[chain[i]]; i++) {
        data = data[chain[i]];      
    }
    
    // Embrace JavaScript Awesomeness!
    

    A breakdown of what I’m doing here:

    In JS any property can be called as object[propertyName].

    That includes arrays, i.e. a[3] is the same as a['3'].

    Therefore, we split the string using one of the characters: ., [, ]. The + is there because without it if you have a[3].b[3] the ]. will give you an empty
    string.

    We might get an empty string in the end, but that’s not a problem since "" is like false in JS.

    You could go further and filter out all the invalid variable names, which in javascript is a name that does not conform to [a-zA-Z_$][0-9a-zA-Z_$]*. But I am not quite sure as to why one would do that…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this string: S40102S40078S40079S40080S40053S40052S40051S40050 but my code of Dim MyArray() As String =
I have string like this : <input name=my_name id=my_id value=my_value class=my_class /> I would
I have a array of string myArray[] in my jQuery the value is generated
So I have a method which instantiates a instance field String[][] myArray with values.
I have an array of strings like this: using std::string; string myArray[] = {
I have an array: string myArray={15,56,17-75,78,100-150,130} I want to filter myList by arrayElements .
I have string that look like Array that fetched from other webservice like this
I have string that displays UTF-8 encoded characters, and I want to convert it
I have string as abvd.qweqw.sdfs.a=aqwrwewrwerrew . I need to parse this string and get
I have string like \LESSING\root\cimv2:Win32_UserAccount.Domain=LESSING,Name=Admin How to convert it to LESSING\Admin using Framework?

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.