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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:47:56+00:00 2026-06-04T04:47:56+00:00

var events = [ {id: 100,url: mc.jsp?id= + id}, {id: 200,url: mc2.jsp?id= + id},

  • 0
var events = [
    {id: 100,url: "mc.jsp?id=" + id},
    {id: 200,url: "mc2.jsp?id=" + id},
    {id: 300,url: "mc2.jsp?id=" + id}
]

When run, the url equals mc.jsp?id=undefined,
so how can assign the id (100) to the url to get the value of mc.jsp?id=100?
And also make the second url as mc2.jsp=200 and third one mc2.jsp?id=300
so I cannot make assignment outside the array.

  • 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-04T04:47:58+00:00Added an answer on June 4, 2026 at 4:47 am

    You can’t access other properties in an object literal on constructions. You get an undefined because you have no variable id. You will need to use:

    var id = 100;
    var events = [{"id":id, "url":"mc.jsp?id=" + id}];
    

    or:

    var event = {id: 100};
    event.url = "mc.jsp?id=" + event.id
    var events = [event];
    

    but you could define a getter:

    var events = [{id: 100, get url() { return "mc.jsp?id="+this.id; } }];
    

    which is very complicated and difficult to understand. Maybe it’s better to do something like this:

    function MyEvent(id, mc) {
        this.id = id;
        this.mc = mc;
    }
    MyEvent.prototype.getUrl = function() {
        return "mc"+this.mc+".jsp?id="+this.id;
    };
    
    var events = [new MyEvent(100, ""), new MyEvent(200, "2"), ...];
    

    However, there should be no such problem. If you hardcode the numbers, why don’t you hardcode the urls? If you don’t want the redundancy, just don’t store the id two times and append it each time you need it.

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

Sidebar

Related Questions

how can we make a date shown in bold format? var events = {};
i can reference link with specific id with following code $(document).ready(function(){ $(a#example_link_id).click(function(event){ var url
I am creating a user input at one of the events: var throwConnectBox =
I understood how to create events, like that: var evt=document.createEvent('Event'); evt.initEvent('foo',true,true); window.dispatch(evt); Then anyone
I have this code: $.getJSON(Featured/getEvents, function(data){ $.each(data.events, function(i,event){ var title = event.title.substr(0,20); $(#title-+i).text(Text); if
I have a timer script: import flash.utils.Timer; import flash.events.TimerEvent; var secs:Number = 30;//second var
How can I get this error from with in the DownloadStringCompleted Event? Doesn't that
I try to get all URL's fro this page ( http://www.fotocommunity.de/fotograf/tu-fotodesign/fotos/794400 ) with jquery.
I wrote these lines in My Application start event: var mongo = new Mongo();
My JavaScript code is as follows: $(document).keydown(function(event){ var move, inter; clearInterval(inter); inter = setInterval(move

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.