Error message indicating an attempt to access a property of an undefined object

When attempting to utilize an array to achieve a specific outcome, I encounter the cannot read property of undefined error. Oddly enough, when I console log the same property, I get the desired result. Below is my code:

for (var j=0;j<$scope.ftListe.length;j++){
    if(task[j].projet_id==id){
        if(temp!=task[j].NomTache)
            temptache.push(task[j]);
        tempcol.push(lecollaborateur[j]);
    }
    temp=task[j].NomTache;
}
$scope.temptache=temptache;
$scope.tempcol=tempcol;

for(var i=0; i<temptache.length;i++){
    for (var k=0;k<$scope.ftListe.length;i++){
        console.log("l'id de la tache: "+temptache[i].IdTache);
        if(temptache[i].IdTache==$scope.ftListe[k].tacheid){
            temps = temps+$scope.ftListe[k].TempsPasse;
            passe= passe+$scope.ftListe[k].TempsPasse * lecollaborateur[k].CoutParJour;
        }
    }
    tempsAr.push(temps);
    passeAr.push(passe);
    temps=0; passe=0;
}

The issue arises with the IdTache property. What could be causing this error?

Answer №1

Please review the following code snippet:

for(var i=0; i<temptache.length;i++){
    for (var k=0;k<$scope.ftListe.length;i++){

Notice that in the inner for loop, you are incrementing the i variable (i++) instead of k. This causes the i to be incremented within the inner loop, leading to an offset that is out of bounds.

The JavaScript runtime error prevents your script from entering an infinite loop - When you mentioned that "when I console log that same property I get my result", it actually displays results only up to the valid range of the temptache array.

To correct this issue, the code should be modified to:

for(var i=0; i<temptache.length;i++){
    for (var k=0;k<$scope.ftListe.length;k++){

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

Utilize React.js ThemeProvider to dynamically change themes based on routing

Hey everyone, I have a question regarding changing the theme provider based on the route in my code snippet: const rootElement = document.getElementById('root'); ReactDOM.render( <ThemeProvider theme="MyThemes.default& ...

What is the best way to generate a random string output from an object in JavaScript?

I'm struggling with extracting a random value from the object provided below, can anyone help me out? const hellos = { English: "Hello", Japanese: "Konnichiwa", German: "Hallo", Spanish: "Hola", Arabic: "Ah ...

Vue infinite loop occurring in a method

I keep receiving this warning [Vue warn]: You may have an infinite update loop in a component render function. and I believe I have pinpointed the reason behind it. My Scenario : I am passing an object with an index to a Vue method within a loop. Computed ...

Passing variables by reference in JavaScript allows for direct manipulation of

Is there a JavaScript equivalent to PHP's method of passing variables by reference? [PHP]: function addToEnd(&$theRefVar,$str) { $theRefVar.=$str; } $myVar="Hello"; addToEnd($myVar," World!"); print $myVar;//Outputs: Hello World! If possible, h ...

"Developing a Node.js API for a REST service with text translation and email functionalities using Node

I've created a REST API using node js and express to handle user registrations. When a user registers, a confirmation email is sent using node mailer. The API also includes authentication services where the app passes a language code and receives an e ...

Generate a separate div in an HTML file for each item listed in a JSON document

I have a JSON file structured like this: { "text": "HelloWorld", "id&quo;t: "1", }, { "text": "HelloMoon", "id": "2", } Now, I want to generate a <div> in my HTML for ...

Fetch search results dynamically in Wordpress through AJAX

I'm struggling to implement AJAX on my WordPress site to display search results without refreshing the page. Despite trying various solutions found through research, none seem to be working effectively for me. Currently, here is the progress I have ma ...

Generate unique Prometheus gauge names on the fly

Incorporating prom-client into my node application allows me to send statistics to our prometheus platform. To check the availability of different applications, I am initiating a series of requests. In this process, I aim to customize the name of the gauge ...

Is there a way to eliminate an item from a Redux/React array state?

I am having trouble removing an object from an array onClick when I click on the delete button. I have written some code in my redux and react but it is not functioning as expected! Reducers import { ActionsTypes } from "../Constant/ActionsTypes" ...

Scaling up the window size in Scalatest PlusPlay Selenium is causing resizing issues

After spending a good amount of time on this, I am struggling to figure out how to resize a window using scalatest plus. I have searched online and looked through the documentation at The method I found is executeScript("window.resizeTo(700, 700);") ...

jsPDF is ready to create a PDF based on user input, however, the current page is not showing any updates

Currently, I am facing an issue with my static page that contains HTML/form checkboxes. Only the selected checkboxes are included in the JS-generated PDF, and the content is replaced from 'checkbox' to HTML via the parent div. However, when the & ...

Having trouble getting ngInfiniteScroll to cease scrolling

I've been struggling with a web page that just won't work correctly. Despite using AngularJS, Foundation, and ngInfiniteScroll, the loadMore() function keeps getting called endlessly on this template: <div class="row"> <div class="sma ...

Uncovering the secrets: accessing hidden folder files in react-native-fs

I am encountering a problem when trying to access files from a hidden folder /WhatsApp/Media/.Statuses in react-native-fs. Despite granting the READ_EXTERNAL_STORAGE permission on Android, I only receive an empty array when attempting to access it using th ...

Is it possible to have content in an array with a length of 0?

Here is the test code that I am using: console.log('AA',slider); console.log('AB',slider.length); When I check the Chrome console, it shows the following results. AA Array[53] AB 0 I included this test code because even though there ...

Text that is curving around a D3.js pie chart

I am currently working on creating a 3D-Js chart and I would like the pie text to wrap around the pie itself. This is the exact effect that I am trying to achieve: https://i.sstatic.net/YOLdo.png I am facing two main issues: I am currently printi ...

Choosing items by pressing "shift + up arrow"

I have a collection of elements, each representing one line of text. When you click on an element, it changes color. If you then hold down "shift + arrow up," the items above it are also selected. How can this functionality be implemented? My initial app ...

Execute angular function as you scroll upwards in a chat application with pagination feature

I'm currently working on a chat application and looking to implement pagination upon scrolling up (not down). I am in need of a directive for this task. Additionally, I would like to display a preloader while loading new page data. Can someone advise ...

Sending data from a PHP URL to JavaScript and then to another PHP file

After referencing the code from , I am modifying it to send the recorded audio file to a server by including a sessionId in the URL. The PHP page for this purpose is located at . My PHP versions are PHP 5.4 and PHP 5.5.22. For passing variables and data be ...

Leveraging HeatMap.js, a JavaScript library, within a ReactJS environment

Seeking Assistance I am aiming to implement a heatmapjs running example in ReactJS. How can I achieve this goal? ...

To insert a new row into a table with an onClick function, along with removing this attribute from all other rows except for the newly added one

I recently created a piece of code that enables the addition of a new row and removes an (onClick) attribute when clicking on an existing row within a table. <table style="vertical-align:middle;margin:20px;" id="table_insert"> <tr id="tra" > ...