如何查找“items_tolookfor”的索引另一个嵌套数组列表“nested_data”中的项目数组在 JavaScript 中
如何在javascript中的另一个嵌套数组列表“nested_data”中查找“items_tolookfor”项目数组的索引
const items_tolookfor = []
console.log(items_tolookfor) is as below
0: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
1: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
2: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
3: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
4: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
5: "urn:adsk.wipprod:fs.folder:co._rdgx-sJT36zVaGNILbvvQ"
length: 6
lastIndex: (...)
lastItem: (...)
[[Prototype]]
//////////////////////////////////////////////////////////
const nested_data = []
console.log(nested_data) is as follows:
0: Array(0)
length: 0
lastIndex: (...)
lastItem: (...)
[[Prototype]]: Array(0)
1: Array(0)
length: 0
lastIndex: (...)
lastItem: (...)
[[Prototype]]: Array(0)
2: Array(5)
0: "urn:adsk.wipprod:fs.folder:co.yoqKNIJMTmWvdxFIYGk8sg"
1: "urn:adsk.wipprod:fs.folder:co.eGqoz0IlTriGsYLTKbIrIA"
2: "urn:adsk.wipprod:fs.folder:co.O4tlfhMhSACS81dsygYJSw"
3: "urn:adsk.wipprod:fs.folder:co.FBQOhzXkSa6upov-iay5EQ"
4: "urn:adsk.wipprod:fs.folder:co.nXNGKsqTQUGr_hcTXy6U5g"
5: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
length: 5
lastIndex: (...)
lastItem: (...)
[[Prototype]]: Array(0)
///////////////////////////////////////////
如何在嵌套数组列表“nested_data”中找到“items_tolookfor”的索引 另外,相应的数据位于嵌套列表“nested_data”索引[2][5]中,
我正在尝试以下代码:
console.log(items_tolookfor);
console.log(nested_data);
const found_indices = [];
for (const assdata in nested_data) {
const temp = [];
for (const fldr_data in items_tolookfor) {
const temp1 = assdata.indexOf(fldr_data);
temp.push(temp1);
}
found_indices.push(temp);
}
预期结果是一个控制台日志输出数组,其中包含在nested_data数组对象中找到的items_to_look_for数组对象的匹配数据,即0:[2][5]、1:[2][5]、2:[2][5]、3:[2][5]、4:[2][5]、 5:[][]
How to find index of 'items_tolookfor' array of items in another nested Array List 'nested_data' in javascript
const items_tolookfor = []
console.log(items_tolookfor) is as below
0: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
1: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
2: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
3: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
4: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
5: "urn:adsk.wipprod:fs.folder:co._rdgx-sJT36zVaGNILbvvQ"
length: 6
lastIndex: (...)
lastItem: (...)
[[Prototype]]
//////////////////////////////////////////////////////////
const nested_data = []
console.log(nested_data) is as follows:
0: Array(0)
length: 0
lastIndex: (...)
lastItem: (...)
[[Prototype]]: Array(0)
1: Array(0)
length: 0
lastIndex: (...)
lastItem: (...)
[[Prototype]]: Array(0)
2: Array(5)
0: "urn:adsk.wipprod:fs.folder:co.yoqKNIJMTmWvdxFIYGk8sg"
1: "urn:adsk.wipprod:fs.folder:co.eGqoz0IlTriGsYLTKbIrIA"
2: "urn:adsk.wipprod:fs.folder:co.O4tlfhMhSACS81dsygYJSw"
3: "urn:adsk.wipprod:fs.folder:co.FBQOhzXkSa6upov-iay5EQ"
4: "urn:adsk.wipprod:fs.folder:co.nXNGKsqTQUGr_hcTXy6U5g"
5: "urn:adsk.wipprod:fs.folder:co.uqbu12FFQZO6y7GxUs7cKA"
length: 5
lastIndex: (...)
lastItem: (...)
[[Prototype]]: Array(0)
///////////////////////////////////////////
How would I find indices for 'items_tolookfor' in the nested array list 'nested_data'
Also, the corresponding data lies in the nested list 'nested_data' index[2][5]
I was trying this code:
console.log(items_tolookfor);
console.log(nested_data);
const found_indices = [];
for (const assdata in nested_data) {
const temp = [];
for (const fldr_data in items_tolookfor) {
const temp1 = assdata.indexOf(fldr_data);
temp.push(temp1);
}
found_indices.push(temp);
}
Expected result to be a console log output array with matching data for items_to_look_for array object found in nested_data array object, which is 0: [2][5], 1:[2][5], 2:[2][5], 3: [2][5], 4: [2][5], 5:[][]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以这样做:
Here's how you could go about that: