JSFiddle - React, Tailwind, and code Playground

HTML

<script src="https://unpkg.com/kd-tree-javascript@1.0.3/kdTree.js"></script>

JavaScript

function KDTEST1(){
  let distance=function(a,b){
    return Math.pow(a.x-b.x,2)+Math.pow(a.y-b.y,2);
  }
  let checkLength=function(tree){
    console.log(tree.nearest({"x":0,"y":0},20).length)
  }

  let points=[{"x":-12.67,"y":-17.41083743950336,"index":3},{"x":-12.67,"y":-11.526,"index":16}]
  let tree=new kdTree([],distance,["x","y"]);
  points.forEach(point=>{
    tree.insert(point);
  }) 
  checkLength(tree);
  points.forEach(point=>{
    tree.remove(point);
    checkLength(tree);
  }) 
}

KDTEST1()