JavaScript How do I queue events in a Javascript Loop queue javascript events

I have an array that creates a conversation between two people where it 'flips' between the browser speaking and the browser listening.

Short version, how do I make saySomething queue

 for(var i=0; i < speaks.length; i++) {
     saySomething(speaks[i]);    // saySomething should wait for the previous loop to complete
 }

Long Version

var speak = {}; var speaks = [];
speak.utter = "What do they call a quarter pounder with cheese in Paris?"
speak.speaker = true;
speaks.push(speak);

var speak = {}; 
speak.utter = "They don't call it a quarter pounder with cheese?"
speak.speaker = false;
speak.time = 3;  // listen for 3 seconds
speaks.push(speak);

var speak = {}; 
speak.utter = "They got the metric system. They call it a Royale with cheese"
speak.speaker = true;
speaks.push(speak);

for(var i=0; i < speaks.length; i++) {    //foreach better?
        var speak = speaks[i];
        if(speak.speaker)
              speakThePhrase(speak);    // uses SpeechSynthesisUtterance
        else
              listenAndCompare(speak);  // uses webkitSpeechRecognition
        // don't attempt to speak while listening is happening and vice-versa
    }
 doSomethingElse();    don't process this till old the speaking/listening is done

Originally I had a recursive loop shifting the array and doing much the same as the above but I think this way might be easier to control the queue. So either using jQuery deferred or Javascript Q how would I go about this?

Answer:1

I have a Node.js route that sends back some text and logs the request: app.post('/registerUser', function (req, res) { res.send('Hello World post!') console.log(req); }) Then I hit that route ...

I have a Node.js route that sends back some text and logs the request: app.post('/registerUser', function (req, res) { res.send('Hello World post!') console.log(req); }) Then I hit that route ...

  1. node inspect websockets request was expected
  2. inspect request node.js

I have this array: [{ name: "A1", arr: [1,2] }, { name: "A2", arr: [1] }] How do I can split the first one object to two objects that should contains only one array value? The result should be: [...

I have this array: [{ name: "A1", arr: [1,2] }, { name: "A2", arr: [1] }] How do I can split the first one object to two objects that should contains only one array value? The result should be: [...

  1. split array objects
  2. split array objects javascript
  3. split objects array js
  4. split array into objects
  5. split array of objects php
  6. split array of objects lodash
  7. split array of json objects
  8. split array of json objects python
  9. javascript split array of objects by property
  10. logstash split array of objects
  11. split json array into objects
  12. javascript split array into objects
  13. powershell split array of objects
  14. typescript split array of objects by property
  15. java split array of objects
  16. typescript split array of objects

I am facing issue regarding passing javascript variables to php within same function. My code looks like this else if(msg_type[i] == 'code' ){ var code_action = 'test'; <?php function ...

I am facing issue regarding passing javascript variables to php within same function. My code looks like this else if(msg_type[i] == 'code' ){ var code_action = 'test'; <?php function ...

  1. passing variable from html to javascript
  2. passing variable from javascript to php
  3. passing variable from shell script to jenkins
  4. passing variable from controller to view laravel
  5. passing variable from response to request in jmeter
  6. passing variable from parent to child angular
  7. passing variable from html to php
  8. passing variable from javascript to python
  9. passing variable from js to php
  10. passing variable from js to django view
  11. passing variable from html to node js
  12. passing variable from html to python
  13. passing variable from flask to javascript

I'm trying to get a React component I've built to display on the same line as the rest of the text, but it keeps appearing on a different line than the rest of the elements. Here's my React code: &...

I'm trying to get a React component I've built to display on the same line as the rest of the text, but it keeps appearing on a different line than the rest of the elements. Here's my React code: &...