Error: Unable to access the 'TigerNo' property of an undefined object. Setting tempObj['TigerNo'] to the default TigerNo value from the sports record

  • I need some help with JavaScript programming.
  • Although I am able to retrieve values in sportsRecord, I am encountering difficulties assigning them to tempObj['TigerNo'].
  • Whenever I try to assign the value, I encounter the following error message --

TypeError: Cannot read property 'TigerNo' of undefined tempObj['TigerNo'] = this.getDefault(sportsRecord).TigerNo;

  • Below is a snippet of relevant code and the full code can be found on gist.
  • Can someone please guide me on how to resolve this issue?
  • Here's my code snippet for reference:

https://gist.github.com/niniyzni/5c19f385b35f9418086125799803efe7

TypeError: Cannot read property 'TigerNo' of undefined
    at playerLionUpdate.setNesetTigerstworks (player-LionUpdate.ts:980)
    at SafeSubscriber.eval [as _next] (player-LionUpdate.ts:367)


    getDefault(sportsRecord: any){                                                
        for(var i=0; i<sportsRecord.length; i++){
            if(sportsRecord[i].hasOwnProperty("isDefault"))
            { 
                if(sportsRecord[i].isDefault)
                    return sportsRecord[i];

                break;
            }   
        }
    }

    setTigers(sportsRecord: any) {


        let that = this;
        let tempObj = {};
       
       // Relevant code section
       ...
   
        $("#unSelectedTigersLogoBox1 .currentNwLogo").bind("click", function (e) {
                e.stopPropagation();
                that.singleSelection(sportsRecord, e);
            });

    
    }


sportsRecord = {
        playerTigers:[
            {TigerNo: 237, TigerName: "Bird Bay Area", TigerkGroupNo: 1, isDefault: true, futureAccessDays: ""},
            {TigerkNo: 238, TigerName: "Bird California", TigerkGroupNo: 1, futureAccessDays: ""},
            {TigerkNo: 239, TigerName: "Bird Washington", TigerkGroupNo: 1, futureAccessDays: ""},
            {TigerNo: 240, TigerName: "Bird Philadelphia", TigerkGroupNo: 1, futureAccessDays: ""},
            {TigerNo: 241, TigerName: "TCN", TigerkGroupNo: 1, futureAccessDays: ""},
            {TigerNo: 242, TigerName: "Bird Chicago", TigerkGroupNo: 1, futureAccessDays: ""},
            {TigerNo: 243, TigerName: "Bird Boston", TigerkGroupNo: 1, futureAccessDays: ""},
            {TigerNo: 244, TigerName: "Bird Northwest", TigerkGroupNo: 1, futureAccessDays: ""}
        ]
}

Answer №1

The variable:

sportsRecord.isDefault

has not been configured correctly. Therefore,

this.getDefault(sportsRecord)

will result in

'undefined'

Please ensure to set sportsRecord.isDefault before calling this.getDefault(sportsRecord)

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

Upon reloading, the dynamically generated table does not appear accurately

When a table is dynamically created using JavaScript/jQuery/html from an Ajax call, it initially displays correctly formatted. However, upon refresh/reload, the formatting of the table becomes incorrect. To address this issue, I have implemented a Promise ...

Events in Three.js have an impact on the Document Object Model (

Here's a simple question for you. Is it possible to create click events in a three.js scene that can manipulate the DOM? For example, if an object is clicked in the scene, can it make a panel outside the scene become visible? Thank you! ...

Start a timer in CodeIgniter when a button is clicked and show the time elapsed

Just a heads up: I am currently in the learning process. While I have some experience with PHP, my knowledge of Java is very limited or non-existent. In the past, I've received negative feedback due to this lack of experience. So, here I am giving it ...

Utilizing a filter within the ng-model directive

I have a question about using a filter with an h3 element. Here is the code snippet: {{ event.date | date:'dd-MM-yyyy' }} It's working perfectly fine and Angular is formatting the date as expected. However, when I try to use the same filte ...

Choose three different images and one corresponding word from a JavaScript array to be displayed individually on the screen in separate div containers

I am in the process of developing a web game that will showcase 3 images on the screen, and the player must select the image that corresponds to the displayed word. I have successfully created a JavaScript array containing the images and words retrieved fr ...

Cities cannot be obscured by a rotating globe

In my latest project, I have created a jsfiddle showcasing a Bostock spinning globe implementation. After successfully plotting a few city markers, I encountered a problem where not all cities were being displayed. Additionally, the script intended to hid ...

What is the best way to upload multiple files in Rails 4 using jquery?

Currently, I have integrated an upload form on my site to allow users to upload HTML files. However, I am facing an issue with enabling multiple file uploads simultaneously. I have included the jquery-fileupload-rails gem to permit users to select and uplo ...

The function you are trying to call is not callable. The type 'Promise<void>' does not have any call signatures. This issue is related to Mongodb and Nodejs

Currently, I am attempting to establish a connection between MongoDB and Node (ts). However, during the connection process, I encountered an error stating: "This expression is not callable. Type 'Promise<void>' has no call signatures" da ...

Eliminate server-side functionality from the React project's boilerplate template

After cloning and installing the project from https://github.com/react-boilerplate/react-boilerplate, I realized that I only need the client-side portion as I intend to use a pre-existing server (express) for my application setup. Below is an excerpt f ...

faulty lineup in jquery picture switching feature

I've been working on a website that features a jumbotron with images that transition. I've searched online for solutions, but have come up empty. I know the answer is probably simple, but I just can't seem to figure it out right now. The is ...

I'm curious about the process by which custom hooks retrieve data and the detailed pathway that custom hooks follow

//using Input HOOK I am curious to understand how this custom hook operates. import { useState } from "react"; export default initialValue => { const [value, setValue] = useState(initialValue); return { value, onChange: event =&g ...

Altering the properties of a specified element within TestBed using the overrideComponent method

We are implementing TestBed.overrideComponent() to substitute a component with custom behavior. TestBed.overrideComponent(CoolComponent, { set: { template: '<div id="fake-component">i am the fake component</div>', sel ...

Link several jQuery elements to a function simultaneously

Having 3 jQuery objects is my current situation: var first = $('.el1'); var second = $('.el2'); var third = $('.el3'); I am trying to attach a "change" event to all of them simultaneously, but facing some challenges :( $(fi ...

What advantages does incorporating "function() 'use strict'" into each individual file provide?

As I dive into revamping an older AngularJS 1.3 project, one striking observation is the consistent pattern of starting each AngularJS code file with: (function () { 'use strict'; angular.module('app').factory('Employees', ...

Enhancing Typescript Arrow Function Parameters using Decorators

Can decorators be used on parameters within an arrow function at this time? For instance: const func: Function = (@Decorator param: any) => { ... } or class SomeClass { public classProp: Function = (@Decorator param: any) => { ... } } Neither W ...

Invoke the jquery.load(); function within a preexisting JavaScript file

My goal is to avoid loading javascript with jquery or any similar methods. Currently, I am customizing swfupload (if you are acquainted with it, that's helpful, but not necessary) for a website I am developing. I require the capability to upload, sto ...

Accessing JSON data from a URL for use within a specific context

I am currently utilizing the request module within Express to fetch a JSON file from a specified link. var url = 'https://api.github.com/users/google/repos'; request.get({ url: url, json: true, headers: {'User-Agent': &apo ...

Changing a string-stored array into a List object in JavaString

Here is a messy nested list that I need to convert into a list of numbers: nested_list = [ ["[63]"], ["[61]"], ["[7]"], ["[63]"], ["[80, 18]"], ["[80, 43, 18, 20]"] ] I know it's ...

Is there a JSON API available in Windows that can be accessed through C programming language?

Are there any built-in ways to handle JSON in Windows using C programming? If not, is .NET or C# a better option? Alternatively, what libraries do developers typically use for incorporating JSON into Windows applications? ...

In my React.js project, I am looking to iterate through an array of objects and organize them based on a specific condition

Here is an example of the structure of my JSON file: { "PlanetIdentifier": "KOI-1843.03", "TypeFlag": 0, "PlanetaryMassJpt": 0.0014, "RadiusJpt": 0.054, "PeriodDays": 0.176891 ...