Dealing with undefined properties in Javascript can cause errors

[ { dateTime: '2016-03-30 05:55:53', value: '4.0' },
  { dateTime: '2016-03-30 05:55:55', value: '17.0' },
  { dateTime: '2016-03-30 05:55:57', value: '17.0' },
  { dateTime: '2016-03-30 06:00:51', value: '33.0' } ]

the provided values are stored in the console.log(points.points[tags[0]]) variable, however attempting to access a specific item like console.log(points.points[tags[0]][0]) throws an error as follows: { dateTime: '2016-03-30 06:00:51', value: '33.0' }

when trying to print the individual data elements such as console.log(points.points[tags[0]][0].dateTime), an error occurs with the messages "Cannot read property 'dateTime' of undefined" and "Cannot read property 'value' of undefined".

var data = []; 
        <%
       for (var i=0; i < tags.length; i++)
       { %>
       var dataSeries = { type: "line" };
        var dataPoints = [];

            // var pointdata ="<%= points.points[tags[i]] %>";


        for (var n=0; n < <%= points.points[tags[i]].length %>; n++)
        {

          <%=   console.log(points.points[tags[i]]); %> 

           dataPoints.push({

                 x: <%= points.points[tags[i]][n].dateTime %>,
                 y: <%= points.points[tags[i]][n].value %>
            });
        }
             dataSeries.dataPoints = dataPoints;
             data.push(dataSeries);               
          <% } %>

    </script>

Answer №1

Experiment

points.points[tags[0]][0]["dateTime"]

This could be worth trying out as it utilizes a dictionary data structure.

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

Retrieving information from MySQL using PDO

I am attempting to retrieve data from a database using the code provided below. Additionally, I have a configuration file that contains generic connection details. config.inc.php <?php $servername = "localhost"; $username = "root"; $password = "ro ...

Ensuring jQuery filter() works seamlessly with Internet Explorer versions 6, 7, and 8

On my webpage, I have implemented an ajax call using the jQuery library to handle a specific task. After making the ajax call, I need to parse the response message that is returned. However, I encountered an issue with Internet Explorer versions 6, 7, and ...

JQuery fails to remove the "display:hidden" attribute

List of methods I attempted: Utilizing .removeClass and addClass functions Applying show() and hide() methods Modifying the CSS properties Initially, I confirmed that my script contains onLoad. Furthermore, all other elements are functioning correctly. D ...

What is the process for incorporating a package.json file into a completed React application?

When using the npm build command to build a react app for production environment, we get a build folder containing html, css, and JavaScript files, but the package.json file is missing. If we try to use this file to set an http proxy endpoint for connecti ...

The CSS menu dropdown fails to function properly on desktop view when there is longer content present

I attempted to merge two different navigation bars, one sticky and the other responsive. The goal was to combine https://www.w3schools.com/howto/howto_js_navbar_sticky.asp with https://www.w3schools.com/howto/howto_js_responsive_navbar_dropdown.asp Curr ...

Could not load ngx-restangular due to an error: (SystemJS) Module not yet loaded while trying to load "@angular/core"

Recently, I made the switch from using the AngularJS 'restangular' library to the Angular 'ngx-restangular' library during an upgrade from AngularJS to Angular. However, after the transition, I encountered an unexpected error along wit ...

Could it be possible that my code is preventing any duplicate entries in a table?

Currently, I am in the process of developing an application that utilizes JSON data which is regularly updated with fresh JSON data from a Delphi application that I am concurrently working on. Below is the stored procedure I have created to import this inf ...

What are the steps to customizing a package on atmospherejs.com within meteor.js?

When working with atmosphere in meteor.js, installing a package is typically as simple as using a single command. However, if there is a need to make changes to a specific package for customization purposes, the process becomes a bit more complex. For ex ...

The method "_super" is not supported by the object in igGrid

When using infragistics and igGrid in my application, I encountered a javascript error. The error message reads: "Object doesn't support property or method "_super" Although I understand how to resolve this issue, I have decided to provide a fake ...

Divide the string by spaces

One of the challenges I am facing involves a textarea where users can input messages. The goal is to split the message into an array of words after detecting an '@' symbol, and then search for specific words in that array such as @person1 and @pe ...

Switch between active tabs (Typescript)

I am working with an array of tabs and here is the code snippet: const navTabs: ITab[] = [ { Name: allTab, Icon: 'gs-all', Selected: true }, { Name: sources.corporateResources, Icon: 'gs-resources', Selected: false }, { Name ...

The passport local strategy functions properly when tested with Postman, but encounters a "missing credentials" error when used with axios

I am currently working on creating a login system using passport and a local strategy. Strangely, when I attempt to send the request through axios it doesn't seem to work, although it functions properly with Postman. When using axios, I receive an er ...

Using NodeJS to render a JSON object into an HTML format

Attempting to display a NodeJS object as simple JSON in an EJS template file. The object is defined in NodeJs and displayed in the EJS file using this code: <%= JSON.stringify(objName) %> However, this encoding of double quotes (") is causing the ...

Executing Multiple Requests Concurrently in Angular 5 using forkJoin Technique

Important Note The issue lies in the backend, not Angular. The requests are correct. In my Angular5 app, I am trying to upload multiple files at once using rxjs forkJoin. I store the requests in an array as shown in the code below. However, after adding ...

Extract XML array data into PHP variables

Looking for some help with transferring data from an XML feed generated on one site to another and importing it into a MySQL database. However, I'm struggling because I'm not familiar with arrays broken down into multiple elements. I'm wond ...

Utilizing JavaScript variables to generate a custom pie chart on Google

Greetings! I must admit that I am a novice, especially when it comes to JavaScript. My background is mainly in PHP. Recently, I came across a fantastic pie chart created by Google https://developers.google.com/chart/interactive/docs/gallery/piechart I a ...

Activate the "order evaluation" trigger on the checkout page in Woocommerce

I have implemented the Woocommerce Advanced Shipping plugin created by Jeroen Sormani for managing shipping methods, along with the WooCommerce Pay for Payment plugin developed by Karolína Vyskočilová to add a fixed €5 fee to the "cash on delivery" pa ...

What is the best way to bring in a variable initialized by an IIFE from a JavaScript file into a TypeScript class?

I'm currently working towards integrating the steelseries.js library (found at https://github.com/HanSolo/SteelSeries-Canvas) into a Grafana plugin built with React. It's quite a complex task, but I'm up for the challenge. Right now, my ma ...

Issue with useEffect EventListener in REACT HOOKS

Recently, I attempted to create a simple Snake-Game using REACT. Everything was going smoothly until I encountered an issue with using useEffect for moving the "snake" when a keydown event is triggered. The challenge arose when trying to implement moveSnak ...

Acquiring the content of elements contained within a div container

On a webpage, I have included multiple div elements with unique IDs and the following structure: <div class="alert alert-info" id="1"> <p><b><span class="adName">Name</span></b><br> ...