Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

As you can see in the code, i tried to dynamically create arrays inside an object, it doesn't have a problem when debugging, but when i tried to use push method in the array it throws an error. By the way this is in google app script.

Push function not found in the object [object Object]: TypeError. (line 32, file

var LoopQuestGuildAchievementReward = function (spread_sheet, master_name, is_update) {
  initializeBase(this, MasterBase, [spread_sheet, master_name, is_update]);

  this.guild_achievement_columns = new Object();
  this.create_guild_achievement_columns = function () {
    var guild_achievement_coloumn_names = ['ids', 'event_ids', 'range_starts', 'range_ends', 'incentive_ids'];

    for (var i = 0; i < guild_achievement_coloumn_names.length; i++) {
      if (!this.guild_achievement_columns[guild_achievement_coloumn_names[i]]) {
        this.guild_achievement_columns[guild_achievement_coloumn_names[i]] = {};
      };
    };
  };
};

LoopQuestGuildAchievementReward.prototype.setMaster = function(option) {
  if (!option || !option.summary_values || !option.batch_reward_values) {
    throw "Argument exception.";
  };

  var event_id = option.summary_values[8][0];
  var incentive_values = option.batch_reward_values;
  var incentive_master_id = Commons.getIncentiveId(1, event_id, 5);
  var data_row_number = searchRowNumberWrittenLavelInColumn_(incentive_values, 1, "reach num") + 1;
  var guild_achievement_last_id = Commons.getLatestId("loop_quest_guild_achievement_reward", "ja") + 1;

  this.create_guild_achievement_columns();

  while (data_row_number < incentive_values.length && incentive_values[data_row_number][1] != "") {
    var reach_number = incentive_values[data_row_number][1];
    Logger.log(this.guild_achievement_columns.ids);
    this.guild_achievement_columns.ids.push(guild_achievement_last_id); // <- this where the error message points (line no. 32)
    // this.guild_achievement_columns.event_ids.push(event_id);
    // this.guild_achievement_columns.range_starts.push(reach_number);
    // this.guild_achievement_columns.range_ends.push(reach_number - 1);
    // this.guild_achievement_columns.incentive_ids.push(incentive_master_id);

    guild_achievement_last_id++;
    incentive_master_id++;
    data_row_number++;
  }

  Logger.log(this.guild_achievement_columns);
};
share|improve this question
3  
your "ids" is a object not a array.objects do not have push method.in your for loop ,you create object for "ids".see this line this.guild_achievement_columns[guild_achievement_coloumn_names[i]] = {} –  unikorn Sep 2 '14 at 9:25
    
ah yes, thanks it should be [] not {} –  user2432189 Sep 3 '14 at 2:11

1 Answer 1

After asking my superior he mention that curly braces refer to objects and brackets refer to array.

Object: this.guild_achievement_columns[guild_achievement_coloumn_names[i]] = {};

Array: this.guild_achievement_columns[guild_achievement_coloumn_names[i]] = [];

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.