How to find the distance between two points on a plane in js

/Data can be stored as an array or as an object

let a = {
    
    x:'6', y:10},
        b = {
    
    x: 8, y: 20};
    function distant(a,b){
    
    
        let dx = Number(a.x) - Number(b.x)
        let dy = Number(a.y) - Number(b.y)
        return Math.pow(dx*dx + dy*dy, .5)
    }

Then write a simple example:
insert image description here
click on the debug preview, because we use console.log(a); print on the control panel. So press F12 to view the console view
insert image description here

Guess you like

Origin blog.csdn.net/weixin_43860634/article/details/130989505