2017-12-18 11 views
-1

削除配列内のすべての必要な項目を持っているdoesntの完全な配列を取り除くには:彼らとして[2] [0] & OBJをOBJを取り除くたかったです例えば...削除または「カテゴリ」フィールド</p> <p>REQを持っているdoesntの配列

をカテゴリフィールドを肝炎ません。

JSデータを:

のp/oを期待
var obj=[ 

{"email":"[email protected]","event":"open"}, 
{"ip":"24.38.43.233","email":"[email protected]","category":["webinar"]}, 
{"email":"[email protected]","event":"open"}, 
{"ip":"24.98.43.230","email":"[email protected]","category":["webinar"]}, 
{"ip":"24.77.55.931","email":"[email protected]","category":["webinar"]}, 
{"ip":"44.67.85.456","email":"[email protected]","category":["webinar"]} 

]; 

VAR OBJ = [

{"ip":"24.38.43.233","email":"[email protected]","category":["webinar"]}, 
{"ip":"24.98.43.230","email":"[email protected]","category":["webinar"]}, 
{"ip":"24.77.55.931","email":"[email protected]","category":["webinar"]}, 
{"ip":"44.67.85.456","email":"[email protected]","category":["webinar"]} 

]。

質問は、私は完全に質問を理解していない、シンプルな理解のために...事前に おかげで....

答えて

0

を編集しているが、私はあなたのすべてを取り除くためにしたいと仮定していますcategoryプロパティを持たないオブジェクト。このスニペットはそれを行います。ウル返信用

var obj=[ 
 
    {"email":"[email protected]","event":"open"}, 
 
    {"ip":"24.38.43.233","email":"[email protected]","category":["webinar"]}, 
 
    {"email":"[email protected]","event":"open"}, 
 
    {"ip":"24.38.43.230","email":"[email protected]","category":["webinar"]} 
 
]; 
 

 
var result = obj.filter(participation => participation.hasOwnProperty('category')); 
 
console.log(result);

+0

おかげで、あなたのコードを試してみましたが、それは私の要求に正反対の、「カテゴリ」フィールドを持っているdoesntの配列を結果...私はカテゴリを持っている唯一の配列を必要としています。 ... plsの確認と更新... –

+0

@ jesseoneshmark更新された答えを確認し、私はフィルタ条件を否定しました。 –

+0

おかげさまで、フリーマンさん...コードはうまくいきます。 –

関連する問題