var rundhalsArray = ["50237451_001", "50237451_100"];
var Array = ["50237451_001", "50237451_100", "50236765_001", "50236765_100"];
我有兩個數組,並想只顯示比較它們的這樣的結果,當匹配的項目上面會:比較兩個數組,僅顯示匹配的項目Jquery的
var resultArray = ["50237451_001", "50237451_100"];
var rundhalsArray = ["50237451_001", "50237451_100"];
var Array = ["50237451_001", "50237451_100", "50236765_001", "50236765_100"];
我有兩個數組,並想只顯示比較它們的這樣的結果,當匹配的項目上面會:比較兩個數組,僅顯示匹配的項目Jquery的
var resultArray = ["50237451_001", "50237451_100"];
這是我會怎麼做:
var array1 = ["a", "b", "c", "d", "e", "f"];
var array2 = ["a", "b", "c", "d", "e", "f", "g", "h", "i"];
var foo = [];
$.grep(array2, function(el) {
if ($.inArray(el, array1) != -1) {
foo.push(el);
}
});
alert(" they have the same " + foo);
非常感謝你的有用的片段。幫助了很多@Pedro Estrada –
var rundhalsArray = ["50237451_001", "50237451_100"];
var arr = ["50237451_001", "50237451_100", "50236765_001", "50236765_100"];
var result = [];
$.map(rundhalsArray, function (val, i) {
if ($.inArray(val, arr) > -1) {
result.push(val);
}
});
console.log(result);
請告訴我們你已經嘗試了什麼。 – Krishna
jQuery不提供任何方法。 –
這與你最後一個問題有什麼不同http://stackoverflow.com/questions/20522169/remove-set-of-items-from-an-array-jquery? – j08691