如何在javascript中为动态更改对象添加属性?

时间:2016-03-14 12:21:05

标签: javascript arrays object

考虑这段代码。我将字符串加载到数组中的位置。然后发送字符串以查看它是否发生变化,是否发生变化,添加它。但由于我使用一个简单的数组来执行此操作,因此我无法向数组元素添加属性。

....
var generationOffspring = [];
var offspringScore = 0;

// "load" the offspring into an array, check each offspring if it mutates and then score it.
for(var i = 0; i < amount_offspring; i++)
{
    // "load" text into array
    generationOffspring[i] = start_text;
    // send the string to see if it evolves
    generationOffspring[i] = evolve(generationOffspring[i], target_text);
    // then score the string
    offspringScore = score(target_text, generationOffspring[i]);
    ....

那么如何让offspringScoregenerationOffspring[i]相关联?

0 个答案:

没有答案