如何判断javaScript中展开运算符结果的数据类型?

How to determine the data type of the outcome of the spread operator in javaScript?

spread输出的元素的数据类型是什么?是否可以像数组一样在展开后只调用一个元素?

示例如下:

let ages = [1,2,3,1,4];
let chars = ['a','b','c'];


console.log(ages); // shows array> (5) [1, 2, 3, 1, 4]
console.log(...ages); // shows this> 1 2 3 1 4 - ??

console.log(typeof(ages[1]));// number

console.log(typeof(chars));// object

console.log(typeof(chars[1])); //string

//console.log(typeof(...ages)); - NOT WORKING
//console.log(typeof(...ages[1])); - NOT WORKING

谢谢!

What is the data type of the elements outputted by spread?

数组的每个成员都有自己的类型。

And is it possible to call only one element after spread, like with arrays?

展开的要点是将数组的所有个成员展开。

如果你想访问一个成员,那么你不应该首先使用传播。

console.log(typeof(...ages))

这没有意义。 typeof 告诉您 某些东西 的类型,而不是 很多东西 的类型。

如果您想对数组的每个成员执行某些操作,请使用循环而不是展开运算符。

ages.forEach(member => { console.log(typeof member); });
console.log(typeof(...ages[1]));

同样没有意义。 ages[1] 是数字 2。它不是可迭代对象。你不能传播它。如果您想要该元素的类型,则只需:

console.log(typeof ages[1]);