1

So I am currently trying to overwrite a value in my multidimensional array.....where I want to overwrite a value based on the position of where channel.name is and change the value of the mute state if you will.

So what I want to do is:

  1. Mute value in array
  2. When I call the function to unmute it, I want to replace the "Mute" Value with "Unmute".
  3. Then do the same Mute and effectively toggle values.

The problem is I am currently always pushing the values on over and over like so: [ [ '1447682617.29', 'SIP/487-0000000b', 'Mute', 'Unmute' ] ]

I simply just want to overwrite Mute and Replace it with Unmute.

I have the index part fine its just being able to overwrite that value.

The code I have so far is:

//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")
    }
  }

Any suggestions no doubt its something minor question is what.

1 Answer 1

2

Try change (in both occurence)

channelArr[index].push(mutestate);

with

var channelData = channelArr[index];
channelData[2] = mutestate;
channelArr[index] = channelData;

And if it works, you can try to shorten the code like this

channelArr[index][2] = mutestate;
Sign up to request clarification or add additional context in comments.

1 Comment

Really nice solution!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.