のArrayにオブジェクト配列の比較:私は条件を含むオブジェクトの配列を持っていると私は、単純な配列の値に対してオブジェクトの配列を検索したり、比較しようとしていますJavascriptを
var myObjArr = [ {this: "someval", that: "anotherval" }, {this: "someval", that: "anotherval" }, {this: "someval", that: "anotherval" } ];
それから私は、結果の配列を持っています..
var newArrResults = [ "anotherval", "someval", "anotherval2" ];
結果配列newArrResultsの任意の文字列値に対してmyObjArrをチェックする必要があります。私はそれを多くの方法で試してきましたし、ほとんどの方法は不安定です。私が試した最初の方法はArrayObjectをループとのindexOfを探していました
for(var b = 0; b<myObjArr.length; b++){
if(newArrResults.indexOf(myObjArr[b].this) !== -1 && newArrResults.indexOf(myObjArr[b].that) !== -1) {
// is unstable
// i need to know if there are exact matches in "this & that"
}
が、これは少し不安定のようです:私が試した何
。何かご意見は?助けて?正しい方向に私を導くアイデア?
ですか? – Amit
あなたのオブジェクト配列で変数名 'this'を変更する必要があります。 Javascriptの 'this'はキーワードであり、特定の意味を持っています – Vandesh
オブジェクトとnewArrResults配列にはどのようなデータ型が格納されていますか? –