-1
我有以下目的:JS得到[1]從與項目嵌套數組[0] = someValue中
GLOBALS = [
[...],
[...],
[
[...],
["searchValue", [<interestingInfo>]]
]
]
我想找到一種方式來獲得基於所述searchValue陣列。
編輯:這裏是我的非工作的嘗試:
GLOBALS.map(function(item){
if(item && item.constructor === Array)
return item.map(function(itemLvl2) {
if(itemLvl2 && itemLvl2.constructor === Array)
return itemLvl2.map(function(itemLvl3) {
return itemLvl3 && itemLvl3.constructor === Array && itemLvl3[0] == 'searchValue'
});
else
return false;
});
else
return false;
})
編輯:樣本數據/使用例
在需要這一點是爲了從Gmail獲得所有別名電子郵件地址。你可以讓他們打開Gmail並輸入以下內容到控制檯:
GLOBALS[17][15][1].map(function(item) { return item[1]; })
現在,我嘗試這樣做在一個更通用的方法(即不硬編碼的數組索引)
搜索值是'cfs'
我有一些嘗試與array.map,但與嵌套 – Chris
你爲什麼不使用對象而不是無限的嵌套數組奮鬥?它會讓你的生活更輕鬆。 –
請勿使用'.map()'進行搜索,將其用於映射。使用'.find()'或'.findIndex()'進行搜索。 – nnnnnn