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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:01:03+00:00 2026-05-17T20:01:03+00:00

Hey, Im trying to make a nested array in JS var lines = new

  • 0

Hey,
Im trying to make a nested array in JS

    var lines = new Array(
                    "0"= new Array(
                                0['time']="10:00:00",
                                0['user']="User1",
                                0['content']="Line1",
                                ),
                    "1"= new Array(
                                1['time']="20:00:00",
                                1['user']="User2",
                                1['content']="Line2",
                                ),
                    "2"= new Array(
                                2['time']="30:00:00",
                                2['user']="User3",
                                2['content']="Line3",
                                ),
                    );

Chrome’s debugger tells me the ), at the end of the first nested array is an “Unexpected Token”

  • 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-17T20:01:04+00:00Added an answer on May 17, 2026 at 8:01 pm

    From your code it looks like you’re trying to use PHP-style arrays in JavaScript. JavaScript arrays don’t work like PHP arrays. Here’s something that’s more likely to work:

    const lines = [
      { time: '10:00:00',
        user: 'User1',
        content: 'Line1',
      },
      { time: '20:00:00',
        user: 'User2',
        content: 'Line3',
      },
      { time: '30:00:00',
        user: 'User3',
        content: 'Line3',
      },
    ];
    

    To explain a littler further, in JavaScript you create a new array like this:

    const myArray = [ 5, 10, 15 ];
    

    The square brackets ([]) denote the beginning and end of the array and commas (,) separate the elements of the array. Then, to access the elements, we would do something like this:

    alert( myArray[0] );
    

    …which would give 5 (the first, or “0th,” element in the array).

    Now, whereas PHP has the associative array (array('a' => 1, ...)), in JavaScript there’s no “associative array”; rather, you use an “object literal,” like this:

    const myObject = { a: 5, b: 10, c: 15 };
    

    This creates a new object with properties (you can think of them as keys) named a, b, and c. There are two ways to access a property:

    alert( myObject['b'] );
    alert( myObject.b );
    

    In both cases, 10 (the value we assigned to property b) would be given.

    Now back to your exercise. You’ll see that here we’ve created an array ([]) and given it three elements, each of which is an object literal ({}). To access, say, the user property of the first element, we would do this:

    alert( lines[0].user ); // => "User1"
    

    Edit: If you want to name the elements of the outer array, it must be changed to an object literal, and can be nested like so:

    const lines = {
      one: {
        time: '10:00:00',
        user: 'User1',
        content: 'Line1',
      },
      two: {
        // ...
      },
      // ...
    };
    

    I’ve named the items one, two, etc. for clarity’s sake, but you can use any values you please. However, if you intend to use numeric property names—0, 1, 2, etc—as in your example code, you may as well use the other array rather than the object. Unlike PHP, JavaScript does not allow “gaps” in an array—they’ll be filled with undefined. For example:

    const myArr = [1, 2];
    myArr[5] = 3;
    alert( myArr ); // => [ 1, 2, undefined, undefined, undefined, 3 ];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey everyone. I'm trying to make a swing GUI with a button and a
Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my
Hey having some trouble trying to maintain transparency on a png when i create
Hey everyone, I am trying to run the following program, but am getting a
Hey, I am trying to write a command to print todays date on the
Hey! I am not trying to push my luck here but I have another
Hey so what I want to do is snag the content for the first
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey, I'm using Levenshteins algorithm to get distance between source and target string. also
Hey all, my Computational Science course this semester is entirely in Java. I was

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.