Remove some elements from serializeArray()

1.1k views Asked by At

this is my serializeArray.I want get only these 2 push attributes only.other elements in form don't necessary. how to remove others and only keeps these two push values(Attributes and Actions)

 var a = this.serializeArray();
                a.push({name: "Attributes", value:RuleConfigs.attributeContainers});
                a.push({name: "Actions", value:RuleConfigs.actionsContainers});
                $.each(a, function() {
                    if (o[this.name] !== undefined) {
                        if (!o[this.name].push) {
                            o[this.name] = [o[this.name]];
                        }
                        o[this.name].push(this.value || '');
                    } else {
                        o[this.name] = this.value || '';
                    }
                });
                return o;
            };

this is where I call it.

var option=$('form').serializearray();
1

There are 1 answers

2
Jaydip Jadhav On

I think you may looking for this

 var result =[];
 a.map(function(item){
     if(item.Name = 'Attribute' ||  item.Name = 'Actions' ) 
         result.push(item);
 })
 console.log(result);