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

  • SEARCH
  • Home
  • 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 8583475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:32:51+00:00 2026-06-11T21:32:51+00:00

Say I have an object such as this: var time = { ‘second’: 1000,

  • 0

Say I have an object such as this:

var time = {
    'second': 1000,
    'minute': 1000 * 60,
    'hour'  : 1000 * 60 * 60,
    'day'   : 1000 * 60 * 60 * 24,
    'week'  : 1000 * 60 * 60 * 24 * 7
};

How would I shorten it so it would reference the other keys?

I mean something like this:

var time = {
    'second': 1000,
    'minute': this.second * 60,
    'hour'  : this.minute * 60,
    'day'   : this.hour   * 24,
    'week'  : this.day    * 7
}

I can’t reference each using time.foo because the variable isn’t initialized yet. I could simply add each on a new command, such as time['hour'] = time.minute * 60;, but I’d rather do it in one command.

  • 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-11T21:32:52+00:00Added an answer on June 11, 2026 at 9:32 pm
    var time = (function(){
        var second = 1000,
            minute = second * 60,
            hour = minute * 60,
            day = hour * 24,
            week = day * 7;
        return {
            'second': second,
            'minute': minute,
            'hour'  : hour,
            'day'   : day,
            'week'  : week
        };
    })();
    

    UPD

    Even shorter:

    var time = (function(){
        var w, d, h, m, s;
        w = (d = (h = (m = (s = 1000) * 60) * 60) * 24) * 7;
        return {
            second: s,
            minute: m,
            hour  : h,
            day   : d,
            week  : w
        };
    })();
    

    And finally the minified version of this:

    var time=function(){var a,b,c,d,e;a=(b=(c=(d=(e=1e3)*60)*60)*24)*7;return{second:e,minute:d,hour:c,day:b,week:a}}()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a simple object such as class Something { public int SomeInt
Say I have an object-like data record like this: $article = array( 'title' =>
Let's say you have an object literal: var d = { x: +'35', y:
Say I have a Hashtable<String, Object> with such keys and values: apple => 1
So say I have an object/pointer/whatever the definition of such a thing is: A*
I have in a json object which stores a JavaScript say var jsonObj =
Let's say I have objects which look very roughly like this: class object {
Let's say I have a domain object that looks like this: @Entity @Indexed public
If I have a javascript object/assoc. array defined like this: function somefunction(options) { var
So let's say we have a domain object such as the following public class

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.