所以我正在尝试覆盖多维数组中的值.....我想根据channel.name的位置覆盖一个值,如果愿意,可以改变静音状态的值。
所以我想做的是:
问题是我目前总是一遍又一遍地推动这些价值:[ [ '1447682617.29', 'SIP/487-0000000b', 'Mute', 'Unmute' ] ]
我只是想覆盖静音并将其替换为取消静音。
我的索引部分很好,只能覆盖该值。
我到目前为止的代码是:
//ARI function to mute channels.
function mute(mutval,mutestate) {
console.log("Muting:" + mutval);
var index = 0;
var findex = false;
for (var i in channelArr) {
var channelArrEle = channelArr[i];
if (channelArrEle[0] == mutval) {
index = i;
findex = true;
console.log("First Part works!")
}
}
if (findex) {
channelArr[index].push(mutestate);
console.log(channelArr);
} else {
console.log("Error")
}
}
//ARI function to unmute channels which have been muted.
function unmute(unval,mutestate) {
console.log("Unmuting: " + unval);
var index = 0;
var findex = false;
for (var i in channelArr) {
var channelArrEle = channelArr[i];
if (channelArrEle[0] == unval) {
index = i;
findex = true;
console.log("First Part works!")
}
}
if (findex) {
channelArr[index].push(mutestate);
//Just added this to see what would happen!
channelArr[index] = mutestate;
console.log(channelArr);
} else {
console.log("Error")
}
}
任何建议毫无疑问都是小问题。
答案 0 :(得分:2)
尝试更改(两次出现)
channelArr[index].push(mutestate);
与
var channelData = channelArr[index];
channelData[2] = mutestate;
channelArr[index] = channelData;
如果它有效,你可以尝试缩短像这样的代码
channelArr[index][2] = mutestate;