好的,我們有這個比較兩個數據庫的sql比較工具,並且發現了HTML中差異的報告。我需要解析它創建的JavaScript來了解有關差異的更多細節。例如,如果顯示500個已更改的存儲過程,則無法根據由誰進行更改或何時進行過濾。但是如果我能解析JS,我可以根據這些標準進行過濾。但是,他們的JS結構非常複雜,主要是嵌套數組,有時甚至低至4級。這是一個顯示4個不同記錄的示例。javascript數組元素是否知道它們的封閉數組?
var createsql = new Array(
new Array(new Array(0, "Error, No SQL Availible")),
new Array (
new Array(0,"-- Stored Procedure", " "),
new Array(0,"", ""),
new Array(1,"--------------------------------------------------------------------------------------", " "),
new Array(1,"/*", " "),
new Array(1,"Procedure : Schema.p_procedure1", " "),
new Array(1,"Description : This process will do something", " "),
new Array(1,"Creation Date : 11/24/2009", " "),
new Array(1,"Created By : John Doe", " "),
new Array(1,"Tables Updated : None", " "),
new Array(1,"*/", " "),
new Array(0, "", "")
),
new Array (
new Array(0,"-- Stored Procedure", " "),
new Array(0,"", ""),
new Array(1,"--------------------------------------------------------------------------------------", " "),
new Array(1,"/*", " "),
new Array(1,"Procedure : Schema.p_procedure2", " "),
new Array(1,"Description : This process will do something", " "),
new Array(1,"Creation Date : 11/24/2011", " "),
new Array(1,"Created By : Jane Doe", " "),
new Array(1,"Tables Updated : None", " "),
new Array(1,"*/", " "),
new Array(0, "", "")
),
new Array (
new Array(0,"-- Stored Procedure", " "),
new Array(0,"", ""),
new Array(1,"--------------------------------------------------------------------------------------", " "),
new Array(1,"/*", " "),
new Array(1,"Procedure : Schema.p_procedure3", " "),
new Array(1,"Description : This process will do something", " "),
new Array(1,"Creation Date : 11/24/2012", " "),
new Array(1,"Created By : Mark Doe", " "),
new Array(1,"Tables Updated : None", " "),
new Array(1,"*/", " "),
new Array(0, "", "")
)
);
我可以解析數組和得到什麼,我這個代碼
var match = "Jane Doe";
var createLength = createsql.length;
var matched;
for(var i = 0; i < createLength; i++){
if(typeof createsql[i] === "object"){
var firstArrayLength = createsql[i].length;
for(var j = 0; j < firstArrayLength; j++){
if(typeof createsql[i][j] === "object"){
var secondArrayLength = createsql[i][j].length;
for(var k = 0; k < secondArrayLength ; k++){
if(typeof createsql[i][j][k] === 'string'){
if((createsql[i][j][k].indexOf(match) != -1)){
console.log(createsql[i][j][k]);
console.log('matched');
//need to grab the parent and search its elemets for the one that starts with the word "Procedure"
}
}
}
}
}
}
}
,但需要什麼我堅持是怎麼做的,我得到了陣列的父母我目前是?例如,如果我的搜索字符串是Jane Doe
,我想要檢索"Procedure : Schema.p_procedure2"
這個元素,它是兄弟數組中的第二個元素。 請別拍我!
PS:爲提高循環任何其他建議,歡迎,這只是一個樣本,這個名單可以大得多。
聖嵌套循環 –
任何人或其他人寫道,JavaScript的第一部分不知道如何編寫JavaScript,因此不應該信任。 JSON的存在是有原因的。 – zzzzBov
對標題的簡短回答:不,項目不知道它們所在的數組。 – Guffa