Kaishu
Kaishu

Reputation: 377

How to create new array element and add at end of array using jquery?

I have an Array of objects and need to add new object as per some criteria. As consist list of objects as:

enter image description here

How to create new object which have all above properties and add to end of array using jquery?

Upvotes: 0

Views: 1221

Answers (2)

madhan kumar
madhan kumar

Reputation: 1608

1.you can create a plain object in jquery

Ex:

var foo = { foo: "bar", hello: "world" };

refer : http://api.jquery.com/jquery/

2.you can create array in jquery

Ex:

var array = new Array();

  1. push elements into an array

Ex: array.push(foo);

refer : https://www.sitepoint.com/declare-arrays-jquery/

Upvotes: 0

Rory McCrossan
Rory McCrossan

Reputation: 337733

You can use the push() method of the array to do this:

// assuming 'arr' is the variable containing the array you showed in the question:
arr.push({
    AgentOnlyFieldFlag: 'False',
    // other properties here...
});

More info on push()

Also note that you should really change the AgentOnlyFieldFlag, BlankCaptionFlag and PromatchFlag to contain boolean values instead of strings.

Upvotes: 1

Related Questions