on 2020 Mar 26 11:12 AM
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
Request clarification before answering.
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();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
11 | |
9 | |
8 | |
7 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.