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

  • SEARCH
  • Home
  • 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 8531799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:34:08+00:00 2026-06-11T09:34:08+00:00

I have the function: function composeLootTables(lootType, result) { for (var d in lootType.items) {

  • 0

I have the function:

function composeLootTables(lootType, result) {
    for (var d in lootType.items) {
        if (result[lootType.title] === undefined) {
            result[lootType.title] = [[0],[0]];
        }
        result[lootType.title][d][0] = lootType.items[d][0];
        result[lootType.title][d][1] = lootType.items[d][1];
        composeLootTables(lootType.items[d][0], result);
    }
    return result;
}

First it parses this:

residential : {
    title: "residential",
    items:[
        [generic, 0.7],
        [military, 0.7],
        [hospital, 0.7],
        [Colt1911, 0.5]
   ]
},

And then others lootType becomes one of these:

var Colt1911 = {
    title: "Colt 1911"
};
var generic = {
     title: "Generic",
     items: [[tin_can, 0.2],[jelly_bean, 0.3]]
};
var military = {
    title: "Military",
    items: [[bfg, 0.2],[akm, 0.3]]
};
var hospital = {
    title: "Hospital",
    items: [[condoms, 0.2],[zelyonka, 0.3]]
};

So, trouble is in this strings:

 result[lootType.title][d][0] = lootType.items[d][0];
 result[lootType.title][d][1] = lootType.items[d][1];

Uncaught TypeError: Cannot set property '0' of undefined 

According to console.log, result[lootType][d] === undefined only when “d” becomes 2 or 3(other times “d” === 0 or 1).

I was assuming that if I will assign value to the undefined field of array, it will be filled with this value.

I already find solution –

result[lootType.title][d] = lootType.items[d];

works fine, it returns proper two-dimensional array, but I want to know what is the deal with those arrays.

  • 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-06-11T09:34:09+00:00Added an answer on June 11, 2026 at 9:34 am

    I’d have to say the problem is the results object that you’re passing as an argument. If it doesn’t have enough arrays created on those indexes, then those locations will be undefined and will throw up when you try to assign to them. Your amended version would work because it copies a reference to an already initialized array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have function source stored in a string eg.: var source=(function(){return Math.sin(x);}); I want
I have function: function get_playlist(){ var result = jQuery.ajax({ url: '<?php echo admin_url('admin-ajax.php'); ?>',
I have function (written in Delphi 7, 32-bit): Function GetVMTAddr(var C): Integer; Begin Result
I have function named: - (void) AddSortedCustomFeed :(NSMutableArray*) rssList; this function adds items(Articles) from
I have: function dosomething(data) { alert($(this).attr('class')) $(this).children('img').attr('title', data) } $('.test').bind('mouseover', function() { $.get('/inc/ajax-function.asp?action=check', dosomething);
I have function like this in my header function bingframe() { var iframe =
I have function like this: $(window).on('scroll', function(){ $('.top_fixed').fadeTo('fast', 0.8); }); I want to return
I have function like this: function ypg_delete_img($id, $img) { $q = $this->ypg_get_one($id); $imgs =
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',

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.