【发布时间】:2020-12-02 05:28:24
【问题描述】:
您好,我正在研究 AngularJS 并尝试将数组推入数组: 这是我尝试过的:
$scope.addPositionInUpdateEditor = function (index) {
$scope.updatePlayersPositionsArray[index].push('PF');
}
我收到错误无法读取未定义的属性“push”。
$scope.updatePlayersPositionsArray 是这种类型的数组:[0:Array(1)[0: "QB"],1: {}]
我想将“PF”值推送到数组结果中的第一个数组应该如下所示:
[0:Array(2)[0: "QB", 1: "PF"],1: {}]
我该怎么做?
【问题讨论】:
-
index的值是多少?如果它不是 0,则会出现该错误。 (如果你想推送到第一个元素,为什么要使用参数呢?) -
谢谢,索引错误
标签: javascript arrays angularjs