0

I have model collection in jquery

thiz.tprListSearchesAndViews.searchParameters[0].parameters

This has 16 parameters list, as shown in the fist screenshot, I need to remove 2 items in the the parameters collection. Could you please help me, how I can do this. I am not getting any idea how I can approach on this using Jquery.

Image2

Image1

Tân
  • 1
  • 13
  • 45
  • 86
Kannan
  • 3
  • 4
  • Check this out: https://stackoverflow.com/questions/3596089/how-to-remove-specific-value-from-array-using-jquery – Marcelo Myara Nov 22 '18 at 18:03
  • It's what you're [probably] looking for. It will show you how to remove elements from a given array using jQuery. – Marcelo Myara Nov 22 '18 at 18:04
  • Thanks Myara, for your response, Basically mine is not simple array, its a complex model collection, so can you please suggest me how To remove items from thr – Kannan Nov 22 '18 at 18:24

1 Answers1

0

removing I think this is what you're looking for:

let resultingArray = jQuery.grep(yourArray, function(obj, idx) {
  //if you want to remove based on some of the element's properties
  //use "obj". E.G.: return (obj['id'] === 3204);

  //Otherwise, use idx for element position on the array.
  return ([1, 7].indexOf(idx) === -1);
});

in your code:

thiz.tprListSearchesAndViews.searchParameters = jQuery.grep(thiz.tprListSearchesAndViews.searchParameters, function(obj, idx) {
  //Filtering by position (removing items at 1 and 7)
  return ([1, 7].indexOf(idx) === -1);
});
Marcelo Myara
  • 2,368
  • 23
  • 34