我正在尝试在 JavaScript 中创建(或模拟)一个无限维数组。本质上,这将是一个将对象与整数列表(可以是任何长度)相关联的数据结构。有没有一种有效的方法来存储这个数据结构中的每个元素?
function addElement(theObject, coordinates){
//object is the object, and coordinates is the list of coordinates (any number of coordinates will be accepted, since it's infinite-dimensional)
}
function getObject(coordinates){
//get the object that was previously assigned to this list of coordinates
}
addElement("Hello World", [0, 0, 3, 5]);
console.log(getObject([0, 0, 3, 5])); //this would print "Hello World".