简体   繁体   中英

How can Javascript returns a string formatted as a gcode co-ordinate

function gcodeXY(source){
    var s = source;
    var f = s.split(",");
    var r = f.join(" ");
    //perhaps split source
    return r;
}

How can Javascript returns a string formatted as a gcode co-ordinate? The picture is the desired input and output, and my current output. So I want to know how I should add X and Y.

在此处输入图像描述

f is an array with 2 elements. You can destructure it and then add X and Y

 function gcodeXY(source){ var [xVal, yVal] = source.split(","); return `X${xVal} Y${yVal}` } console.log(gcodeXY("1,2"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM