-1

I have a huge json array.Now I need to seggregate this array and form another json array.And the condition for that is it should have "dbstatus":-3 in my each json object

  data = [{"id":"122","dbstatus":-3},{"id":"123","dbstatus":"-6"},{"id":"414","dbstatus":-3}]

Now in my new array it should have only following

  data2=[{"id":"122","dbstatus":-3},{"id":"414","dbstatus":-3}]

How can we do this.can someone help

user7350714
  • 365
  • 1
  • 6
  • 20
  • Please have a look at *array.filter()*, it can do exactly what you are looking for: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/filter – Rob Aug 08 '17 at 07:20
  • 1
    Possible duplicate of [Javascript: How to filter object array based on attributes?](https://stackoverflow.com/questions/2722159/javascript-how-to-filter-object-array-based-on-attributes) – Urvashi Soni Aug 08 '17 at 07:25

2 Answers2

2

You can use filter :

var data = [{"id":"122","dbstatus":-3},{"id":"123","dbstatus":"-6"},{"id":"414","dbstatus":-3}];

console.log(data.filter(e => e.dbstatus == -3));
Serge K.
  • 5,303
  • 1
  • 20
  • 27
0

You can use

data.filter(function(o) {return o.dbstatus == -3})
atiq1589
  • 2,227
  • 1
  • 16
  • 24