-2

var data = [{
    "bankId": "67",

    "bankName": "TESTBANKJU",

  },
  {
    "bankId": "52",

    "bankName": "Test",

  },
  {
    "bankId": "50",

    "bankName": "Sanjyot Bank",

  },
  {
    "bankId": "45",

    "bankName": "TestDemo",

  },
];

and get results whose bankId is not 67 and 52

data.filter(x => x.bankId != '67' || x.bankId != '52');

data = [{
    "bankId": "50",

    "bankName": "Sanjyot Bank",

  },
  {
    "bankId": "45",

    "bankName": "TestDemo",

  }
]
2
  • JSON is a textual notation for data exchange. (More here.) If you're dealing with JavaScript source code, and not dealing with a string, you're not dealing with JSON. Commented Jul 11, 2019 at 6:52
  • You literally wrote "and" in your description but wrote "or" in your code. Commented Jul 11, 2019 at 6:52

2 Answers 2

1

It looks like, you need an AND condition. The OR returns every item, because one or both check is always true.

var data = [{ bankId: "67", bankName: "TESTBANKJU" }, { bankId: "52", bankName: "Test" }, { bankId: "50", bankName: "Sanjyot Bank" }, { bankId: "45", bankName: "TestDemo" }]
    result = data.filter(x => x.bankId !== '67' && x.bankId !== '52');

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

Sign up to request clarification or add additional context in comments.

Comments

0

you need && operator.

var data = [{
  "bankId": "67",

  "bankName": "TESTBANKJU",
}, {
  "bankId": "52",

  "bankName": "Test",
}, {
  "bankId": "50",

  "bankName": "Sanjyot Bank",
}, {
  "bankId": "45",

  "bankName": "TestDemo",
}, ]

var filtered_data = data.filter(item => (item.bankId != "67" && item.bankId != "52"))

console.log(filtered_data)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.