Issue with displaying two-dimensional array properly on console

I am currently troubleshooting the following code:

var spacetime = [];
spacetime.push({
    Title : [], 
    Space : [],
    Time : []
});

  if (doSelect('Location').length > 0 && doSelect('Date').length > 0) {
   for(var i = 0; i < dateText.length; i++) {
      d += dateText[i] + ' ';
    }
    if(location.match(regex)) {
      spacetime[0].Title.push("Hello");
      spacetime[2].Time.push(d);
      });
    }
  };

However, when I check the console, I receive the error message:

Cannot read property 'Time' of undefined

Interestingly, d is being output correctly despite this error.

Answer №1

When you added an object to the spacetime array, you only made it available at index 0. Make sure to access it using [0] instead of [2] when setting the Time property:

var spacetime = [];
spacetime.push({
    Title : [], 
    Space : [],
    Time : []
});

if (doSelect('Location').length > 0 && doSelect('Date').length > 0) {
   for(var i = 0; i < dateText.length; i++) {
      d += dateText[i] + ' ';
    }
    if(location.match(regex)) {
      spacetime[0].Title.push("Hello");
      spacetime[0].Time.push(d);
    }
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When evaluating objects or arrays of objects to determine modifications

How can we detect changes in table data when users add input to cells? For example, if a user clicks on a cell and adds an input, the function should return TRUE to indicate that there are changes. If the user just clicks on the cell without making any ch ...

Regex substitute every instance of the phrase CONTAINED within brackets

I am looking to replace all instances of text within brackets, including the brackets themselves, in a given string. The specific text to be replaced will be stored in a variable in Javascript. Using a simple regex in a replace method won't work due t ...

Transform js into a more dynamic format to avoid redundancy when displaying items upon click

I came across a simple lightbox code snippet, but it's based on IDs and I plan to use it for more than 20 items. I don't want to manually write out 20 JavaScript lines when there could be a more efficient way to handle it dynamically. My JS skill ...

What is the best way to extract a message as an object from a JSON data in discord.js?

Currently in the process of developing a discord bot with an election feature for my server's moderator. All the necessary election data is being saved in an external JSON file to ensure that if the bot crashes during an election, it can seamlessly re ...

Exchange information between two selected items

Below is a simplified version of the current code that I am working with: https://jsfiddle.net/2zauty83/8/ Javascript function checkboxlimit(checkgroup) { var checkgroup = checkgroup for (var i = 0; i < checkgroup.length; i++) { checkgroup[i] ...

Converting hexadecimal to binary using Javascript or Typescript before writing a file on an Android or iOS device

Hey everyone! I'm facing a puzzling issue and I can't seem to figure out why it's happening. I need to download a file that is stored in hex format, so I have to first read it as hex, convert it to binary, and then write it onto an Android/ ...

Sort by the date using a specific data attribute

My main objective is to showcase a multitude of posts on this website, sourced from a server that does not organize them by date. I, however, wish to arrange them based on their dates. Currently, the layout on my website looks something like this: < ...

Unable to retrieve an image from various sources

My setup includes an Express server with a designated folder for images. app.use(express.static("files")); When attempting to access an image from the "files" folder at localhost:3000/test, everything functions properly. However, when trying to ...

What is preventing me from accessing arguments.callee within this function in sloppy mode?

In attempting to retrieve the arguments.callee property in the following basic function, I encountered an error preventing me from doing so. function foo(a = 50, b) { console.log(arguments.callee); } foo(10, 50); Why is this issue occurring? It appe ...

Location of the observable space

I have set up a spherical mesh with a texture and positioned a perspective camera to enable a 360-degree view inside out. this.camera = new THREE.PerspectiveCamera(this.fov, $(this.element).width() / $(this.element).height(), 0.1, 1000); this.camera.setLe ...

Issue: Protractor executeScript scroll not functioning properly

A situation has arisen while testing my Ionic app. On a particular page, the button that needs to be clicked is located outside the window boundaries. As a result, the code snippet below produces an error: element.all(by.css('.item.item-complex&apos ...

Using Powershell, my goal is to generate an array through looping and store it in a variable

Below is an example of my code: $original = @("a_1","b_2","c_3","d_4","e_5") foreach ($item in $original) { $splitted = "$item".Split("_") $splitted[0] } The output gives me an array of ...

Can you identify the issue in this PHP script?

After creating a web form for inserting data into a mysql database, I encountered an issue when hitting the submit button. Despite having the correct hostname and other database details, the data was not being inserted as expected. It's likely that t ...

How to Reverse an Array in Java

I have populated an array with numbers from 1 to 10 using a for-loop. Now, I am trying to populate a second array with the values from the first array in reverse order, so the second array should contain numbers from 10 to 1. However, my current attempt i ...

Exploring the Capabilities of Appmobi Codeigniter and Facebook SDK in JavaScript Compared to

Hey there, I know this may not be the most eloquent question, but I could really use some advice on navigating the next phase of my app development journey. This is my first time working with appmobi, so things are a bit confusing for me at the moment. Ty ...

Tips for effectively managing loading and partial states during the execution of a GraphQL query with ApolloClient

I am currently developing a backend application that collects data from GraphQL endpoints using ApolloClient: const client = new ApolloClient({ uri: uri, link: new HttpLink({ uri: uri, fetch }), cache: new InMemoryCache({ addTypename: f ...

Is there a way to extract a variable's value from the URL and distribute it to all links across the website, excluding those on the homepage?

Recently, I was attempting to achieve something similar to this concept how to retrieve variable values from the URL and pass them to all links on a website? However, I encountered an issue where simply visiting the homepage or any other page without the ...

Global jQuery variables are unexpectedly coming back as "undefined" despite being declared globally

I need to save a value from a JSON object in a global variable for future use in my code. Despite trying to declare the country variable as global, it seems like it doesn't actually work. $.getJSON(reverseGeoRequestURL, function(reverseGeoResult){ ...

getStaticProps will not return any data

I'm experiencing an issue with my getStaticProps where only one of the two db queries is returning correct data while the other returns null. What could be causing this problem? const Dash = (props) => { const config = props.config; useEffect(() ...

Tips for swapping images as a webpage is scrolled [using HTML and JavaScript]

Hi there, I am looking to make some changes to a JavaScript code that will switch out a fixed image depending on the user's scrolling behavior. For example, when the page loads, the image should be displayed on the right side. As the user scrolls down ...