var sensor = _this.createSensor("svg", mouse, "sensor_" + timestamp.substring(2, timestamp.length - 2))[0][0];,有人能告诉我函数调用的末尾是什么吗?
下面是我的函数的标题:
DragSensorController.prototype.createSensor = function (parent, startPoint, id, ip, typeid, timestamp) {发布于 2017-07-19 21:06:18
看来:
_this.createSensor("svg", mouse, "sensor_" + timestamp.substring(2, timestamp.length - 2))返回数组的数组,如下所示:
[['foo']]要访问它,您需要使用[0][0]。
const data = [['foo']];
console.log(data[0][0]);
发布于 2017-07-19 21:05:24
createSensor函数可能返回一个数组。例如:
[['item1', 'item2'], ['something1']]
从本质上说,它是从第一个数组中选择第一个项。在本例中,item1
发布于 2017-07-19 21:05:29
这意味着函数返回一个数组,第一个[0]获得对第一个数组元素的引用。然后,该元素本身就是一个数组,因此第二个[0]获得该数组的第一个元素。
function foo(){
var a = [[1,2,3], [4,5,6]];
// Calling this function will return an array consisting of two arrays
return a;
}
// Run the function and get the first item from the first array
console.log(foo()[0][0]); // 1
// Run the function and get the 3rd item from the second array
console.log(foo()[1][2]); // 6
https://stackoverflow.com/questions/45200959
复制相似问题