1

In my first function, I am getting a few pieces of information and pushing them to my object.

  autoArry.push({
        id: countTxns,
        txnID: txnID,
        account: buyersAccount,
        data1: '',
        data2: '',
        data3: ''
    });

At this point, I dont have the information from data1, data2, or data3 but I created them in the object anyway.

Later in my script, I want to be able to fill in those data values when i collect it throughout other functions.

The one thing that I will have that is the same in every function is the txnID.

I assume I will have to Map that somehow and then add additional data that way.

Would anyone be able to explain how I could do this?

Thanks Much

SBB
  • 8,560
  • 30
  • 108
  • 223
  • 1
    Look through this: http://stackoverflow.com/questions/7364150/find-object-by-id-in-array-of-javascript-objects – just_dont Aug 17 '13 at 21:01

1 Answers1

0

Iterate and check for a match :

function otherFunction(txnID) {
     for (var i=0; i<autoArray.length; i++) {
         if (autoArray[i].txnID == txnID) {

             autoArray[i].data1 = 'something 1';
             autoArray[i].data2 = 'something 2';
             autoArray[i].data3 = 'something 3';

         }
     }
}
adeneo
  • 312,895
  • 29
  • 395
  • 388