[Solved] How to add a value to a JSON array of objects?


First of all store the json array in a variable like

var datalist=[{ _id: '58a2b5941a9dfe3537aad540',
    Country: 'India',
    State: 'Andhra Pradesh',
    District: 'Guntur',
    Division: '',
    Village: 'Macharla',
    FarmerName: 'Vijay',
    Address: '',
    Pin: '',
    PrimaryContact: '9160062222',
    OtherContacts: '',
    Email: '',
    updatedAt: '2017-02-14T04:39:01.000Z',
    modifiedBy: '',
    createdAt: '2017-02-14T04:39:01.000Z' },
  { _id: '58a2b5941a9dfe3537aad541',
    Country: 'India',
    State: 'Telangana',
    District: 'Karimnagar',
    Division: '',
    Village: 'Sirisilla',
    FarmerName: 'Subhash Rao',
    Address: '',
    Pin: '',
    PrimaryContact: '8121787878/9441967878',
    OtherContacts: '',
    Email: '',
    updatedAt: '2017-02-14T04:39:01.000Z',
    modifiedBy: '',
    createdAt: '2017-02-14T04:39:01.000Z' },
  { _id: '58a2b5941a9dfe3537aad542',
    Country: 'India',
    State: 'Telangana',
    District: 'Medak',
    Division: '',
    Village: 'Jagur',
    FarmerName: 'Ramachandra',
    Address: '',
    Pin: '',
    PrimaryContact: '9346481116',
    OtherContacts: '',
    Email: '',
    updatedAt: '2017-02-14T04:39:01.000Z',
    modifiedBy: '',
    createdAt: '2017-02-14T04:39:01.000Z' },
  { _id: '58a2b5941a9dfe3537aad543',
    Country: 'India',
    State: 'Telangana',
    District: 'Mahaboob Nagar',
    Division: '',
    Village: 'annugal',
    FarmerName: 'Rajesh Reddy',
    Address: '',
    Pin: '',
    PrimaryContact: '93464593808',
    OtherContacts: '',
    Email: '',
    updatedAt: '2017-02-14T04:39:01.000Z',
    modifiedBy: '',
    createdAt: '2017-02-14T04:39:01.000Z' } ]

then declare another json object and initialize values like

var FinalJsonObject={"draw": 1,
    "recordsTotal": 1,
    "recordsFiltered": 1,
    "data": datalist}

0

solved How to add a value to a JSON array of objects?