Convert SVG Path D Attribute To A Array Of Points
Answer : The SVGPathElement API has built-in methods for getting this info. You do not need to parse the data-string yourself. Since you stored a selection for your line as a variable, you can easily access the path element's api using myLine.node() to refer to the path element itself. For example: var pathElement = myLine.node(); Then you can access the list of commands used to construct the path by accessing the pathSegList property: var pathSegList = pathElement.pathSegList; Using the length property of this object, you can easily loop through it to get the coordinates associated with each path segment: for (var i = 0; i < pathSegList.length; i++) { console.log(pathSegList[i]); } Inspecting the console output, you will find that each path segment has properties for x and y representing the endpoint of that segment. For bezier curves, arcs, and the like, the control points are also given as x1 , y1 , x2 , and y2 as necessary. In your case, regardless of whether yo...