1
這裏是一個小例子裏面:如何尋找一個String對象的數組(結構)
var distinctValues = [];
distinctValues.push("Value1");
distinctValues.push("Value2");
var firstValue = distinctValues[0];
var searchResults = [];
var data = grid.jqGrid('getGridParam', 'data');
data.forEach(function (row) {
searchResults[searchResults.length] =
{
"ID" : row.ID,
"CreatedBy": row.CreatedBy,
"UpdatedBy": row.UpdatedBy
}
}
我看上去怎麼樣firstValue(「值1」)SearchResult所陣列並檢索CreatedBy信息?
//something like this - this is wrong syntax by the way
if ($.inArray(firstValue, searchResults) != -1) {
alert(searchResults["CreatedBy"]);
}
我們可以使用'ARR [arr.length]'添加元素..但'arr.push'更最快 – rab
@ rab猜猜OP的問題是與索引器... – PSL
不幸的是,總是返回-1。我調試它,並可以看到該值存在於數組中:-( – Max