我将两个数组放入一个数组中,但不能将它们用作字符串,这会导致以下结果:一个数组中包含两个数组:
Array(0) [] //This is empty array that I create before and push these two array bellow to them
length:2
0:Array(1) ["cfdb9868-0f69-5781-b1e4-793301280788"]
1:Array(1) ["cfdb9868-0f69-5781-b1e4-793301280788"]
我创建了一个 for 来访问它们,但我可以!我写了这段代码“
for(var index = 0 ; index < Array.length ; ++index) {
let Each_String_In_Brackets = Array[index] ;
console.log(Each_String_In_Bruckets);
}
为什么会出现这种情况!
我的意思是为什么当我们将数组插入空数组时无法访问它们! 我想访问它们的内容,每个括号中有一个字符串。
最佳答案
var arr = [];
arr.push(["cfdb9868-0f69-5781-b1e4-793301280788"]);
arr.push(["cfdb9868-0f69-5781-b1e4-793301280788"]);
//assuming inside array always will be one element:
arr.forEach((item)=>{ console.log(item[0])})
//if inside array may be multiple elements, then use this
arr.forEach((item, index)=>{
item.forEach((child)=>{ console.log(child)})
})
关于javascript - Puh 数组位于之前创建的空数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60337534/