我有一个动态对象,它将添加新对象并更新现有数组。我需要检查以下问题
- 数组是否还有另一个数组?
- 如何从数组的数组中获取数据?
下面是数组对象
[
"Stories",
"Tasks",
"In Progress",
"In Review",
"Completed",
[
{
"divName": "content-container2",
"content": "us 2345",
"topPos": 109,
"leftPos": 150
},
{
"divName": "content-container3",
"content": "Description",
"topPos": 98,
"leftPos": 382
},
{
"divName": "content-container4",
"content": "12212",
"topPos": 110,
"leftPos": 644
}
]
]
最佳答案
我正在谈论我所理解和所知道的
我不知道是否有任何内置函数,您可以迭代数组并得到答案。
Ques:- wheather array has another array?
您可以使用Array.some为此,如下所示。
var arr = [1,2,3,[1,2,3],5]
arr.some(function(element){
return Array.isArray(element)
})// returns true
如果任何元素是数组,它将返回true
。
Ques:- how to get data from array of array ?
您可以使用forEach
并检查它是否是一个数组访问元素
var arr = [1,2,3,[1,2,3],5];
arr.forEach(function(element){
if(Array.isArray(element)){
console.log(element[0])
}
}); //prints 1
如果它提供了一种开始的方式,那就太好了。
注意:- IE8 不支持 Some
和 ForEach
。 for
循环将起作用。
关于javascript - 获取并检查数组的 javascript 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25257308/