-1

I would like to know how to remove particular key value pair in nested array object. But I need to get all the object. how to do in javascript.

In the below obj, remove the mon key value pair and fetch the obj in javascript

var result = getObj(obj, "mon");
getObj(arr, month){
   return arr.filter(element=>
        if (element != month){
            return element
        }
    );
}

var obj =[
  {id: 1, mon: "Dec", tot: 1000},
  {id: 2, mon: "tues", tot: 2000}
]

Expected Output:

[
  {id: 1, tot: 1000},
  {id: 2, tot: 2000}
]
miyavv
  • 763
  • 3
  • 12
  • 30

1 Answers1

0

Try by using below syntax ......

array.splice(index, 1);
Olyve
  • 701
  • 1
  • 8
  • 27
  • I am not sure that this actually solves the problem the OP is having. Could you elaborate and give more information as to why this would work. Maybe even reference some of the original code in your example. – Olyve Feb 10 '20 at 05:56