This is my first Java Script app.
I am writing a music application, and one of its parts must play the notes that are stored in a two-dimensional array in turn. I use setTimeout()
for this with a periodically increasing delay so that the notes are played sequentially.
the problem is that setTimeout()
causes a function play(...)
without delay and all notes sound simultaneously
UPD: I changed my code as advised in the comments, replaced the fore..in with foreach, the problem remained the same
function playAll() {
var j = 0;
noteArr.forEach(function (item,i,arr) {
var delay = 500 * j;
j++;
item.forEach(function(item,i,arr){
setTimeout(play(item), delay);
});
});
}