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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:33:38+00:00 2026-05-26T00:33:38+00:00

So the following won’t work: var Foo = { array1 : [‘apples’, ‘oranges’, ‘grapes’],

  • 0

So the following won’t work:

var Foo = {
    array1 : ['apples', 'oranges', 'grapes'],
    arrayLength : array1.length // error
}

Is there any way I can access Foo.array1‘s length within the object?

  • 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-26T00:33:38+00:00Added an answer on May 26, 2026 at 12:33 am

    You’ll need to do it like this:

    var Foo = {};
    Foo['array1'] = ['apples', 'oranges', 'grapes'];
    Foo['arrayLength'] = Foo['array1'].length;
    

    Or like this (much cleaner IMHO):

    var Foo = function() {
       var a = ['apples', 'oranges', 'grapes'];
       return {'array1': a, 'arrayLength':a.length};
    }();
    

    Another alternative:

    function Foo(array) {
       this.array1 = array;
       this.arrayLength = array.length;
       //other stuff...
    }
    
    var f = new Foo(['apples', 'oranges', 'grapes']);
    

    But really, this doesn’t make much sense to me, you’re already storing the array, why do you need to cache the length property?`

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

Sidebar

Related Questions

I have the following code that won't compile and although there is a way
Can anyone enlighten me why the following won't work? $ groups staff btgroup $
I understand that the following code won't work Float a=3 because its translated as
I got the following code to work with .animate, but it won't with standard
How can I recognise input of the Enter key? The following code won't work
I know there is something dead simple I'm missing, but the following code won't
Can anyone tell me why the following won't work? It complains of a syntax
The following code won't compile on Mac OS X 10.6; it gives an error
I have the following code and I can't figure out why it won't work:
The following won't work: /bin/sleep $(printf .%02ds $(( $RANDOM % 100 ))) POSIX sleep

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.