Skip to content

jQuery.param returns &undefined= as part of the string when looping over a empty array element #4284

@jkesseler

Description

@jkesseler

Description

jQuery.param returns &undefined= as part of the string when looping over a empty array element

Given the following code:

    var condition = false;
    var myArray = [
        { name: 'name1', value: 'value1' },
        condition && { name: 'name2', value: 'value2' },
        { name: 'name3', value: 'value3' },
    ];

    var serialized  = $.param(myArray);
   // output= 'name1=value1&undefined=&name3=value3'
  • What do you expect to happen?
    The returned string does not include '&undefined='

  • What actually happens?
    The returned string includes '&undefined='

Link to test case

http://jsfiddle.net/vedghafn/

Is this desired behavior? The documentation page on jQuery.param() does not mention this. A simple solution would be to check if this.name actually exists before calling add() in serialize.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions