cancel
Showing results for 
Search instead for 
Did you mean: 

can we convert fields insdie the array and give indexs to identify the value

former_member338801
Participant
0 Kudos
219

Hi Experts,

I have one scenario where I am getting records inside the array like attached in the screenshot. Can I convert this in the array again and give indexes to each fields. Actually here I am getting duplicate fields which one empty and one value entered by the user. If I am able to give indexes then it can be used for condition further. array-records.png

Transports: Array(2)0: {ZZ_PKGNUMBER: "", ZZ_SEQNUMBER: 1, ZZ_TRANSPORTNBR: "PORTAL", ZZ_TRANSPDESC: "", ZZ_QA_APPROVER: "", …}1: {ZZ_PKGNUMBER: "", ZZ_SEQNUMBER: 2, ZZ_TRANSPORTNBR: "PORTAL", ZZ_TRANSPDESC: "", ZZ_QA_APPROVER: "", …}length: 2
View Entire Topic
voyager
Product and Topic Expert
Product and Topic Expert
0 Kudos

So currently, there is a big object with many entries on position 0 in your array. You want to have each entry of the object in its own position in the array. If I understand it correctly, try this sample.

// your current array
var aArray = [{"zz1":"1", "zz2":2, "zz3":"3", "zz4":4}];

// loop all entries of the object
Object.keys(aArray[0]).forEach(function(sKey) {
    var oObject = {};
    // create a new object with only one entry
    oObject[sKey] = aArray[0][sKey];
    // add the new object to the array
    aArray.push(oObject);
});
// remove the object that had all entries from the array
aArray.shift();
former_member338801
Participant
0 Kudos

Thanks Nicolas