I have been trying to use the unshift function with a MD array, and I cannot get it to work accordingly.
I am using shift okay and it does what is needed like expected but unshift does not.
Below is the array which I am using:
[ [ '487', 'RINGING' ], [ '477', 'RINGING' ] ]
When I try and do an unshift on it it displays the following:
[ [ '487', 'RINGING' ], [ '477', 'RINGING' ], 2 ]
I simply need to move 477 array to the beginning like so:
[ [ '477', 'RINGING' ], [ '487', 'RINGING' ]]
The code I am using:
var channelArrStatus = [ [ '477', 'RINGING' ], [ '487', 'RINGING' ]];
function monitor_channel(event, channel) {
if (event.device_state['state'] === "RINGING") {
var name = "User_487";
var status = "NOT_INUSE"
var index = 0;
if (channelArrStatus.length === 0) {
var chanar = new Array(name, status);
channelArrStatus.push(chanar);
} else {
var found = false;
for (var i in channelArrStatus) {
var channelArrStatusElem = channelArrStatus[i];
if (channelArrStatusElem[0] === name) {
index = i;
found = true;
if (channelArrStatus[index][1] !== "DND") {
channelArrStatus.push(channelArrStatus.unshift());
setTimeout(function () {
channelArrStatus[index][1] = status;
}, 10000);
}
}
}
}
}
I cant get it to move an array to the beginning of the array as highlight above using unshift.
Any suggestions?
EDIT:JSFiddle