Robotics StackExchange | Archived questions

How can i reach the array out of document ready function?

I've got an array created out of the document ready function, and i need to reach it inside the document ready scopes.

var outarray= [];
var i =0;

var cmdSonarTopic0 = new ROSLIB.Topic({
    ros : ros,
 name : '/gazebo/sensor/Sonar0',
 messageType : 'sensor_msgs/Range'
});

cmdSonarTopic0.subscribe(function(message) {
    outarray.push(message.range);
    console.log(outarray[i]);
    document.getElementById("abc").innerHTML = outarray[1];
    i++;
  });

$(document).ready(function(){
    $("#xyz").text(outarray[1]);
    var inarray= [];
    inarray = outarray; 
    ...
});

<div>
  <p id="abc"></p>
  <p id="xyz"></p>
</div>

Asked by minerva on 2015-05-15 19:04:04 UTC

Comments

Answers