troubleshooting Question

Postman Test (Javascript) issue with looping an array

Avatar of Eddie Shipman
Eddie ShipmanFlag for United States of America asked on
JavaScript* postman
4 Comments1 Solution68 ViewsLast Modified:
Let's say that I have the following Postman test:
    
    var U = data.vCustomer.userDefFlds;
    tests["UDF1  : Matched"] = U[0].udfValue === "CUST_UDF1";
    tests["UDF2  : Matched"] = U[11].udfValue === "CUST_UDF2";
    tests["UDF3  : Matched"] = U[22].udfValue === "CUST_UDF3";
    tests["UDF4  : Matched"] = U[33].udfValue === "CUST_UDF4";
    tests["UDF5  : Matched"] = U[44].udfValue === "CUST_UDF5";
    tests["UDF6  : Matched"] = U[46].udfValue === "CUST_UDF6";
    tests["UDF7  : Matched"] = U[47].udfValue === "CUST_UDF7";
    tests["UDF8  : Matched"] = U[48].udfValue === "CUST_UDF8";
    tests["UDF9  : Matched"] = U[49].udfValue === "CUST_UDF9";
    tests["UDF10 : Matched"] = U[1].udfValue === "CUST_UDF10";
    tests["UDF11 : Matched"] = U[2].udfValue === "CUST_UDF11";
    tests["UDF12 : Matched"] = U[3].udfValue === "CUST_UDF12";
    tests["UDF13 : Matched"] = U[4].udfValue === "CUST_UDF13";
    tests["UDF14 : Matched"] = U[5].udfValue === "CUST_UDF14";
    tests["UDF15 : Matched"] = U[6].udfValue === "CUST_UDF15";
    tests["UDF16 : Matched"] = U[7].udfValue === "CUST_UDF16";
    tests["UDF17 : Matched"] = U[8].udfValue === "CUST_UDF17";
    tests["UDF18 : Matched"] = U[9].udfValue === "CUST_UDF18";
    tests["UDF19 : Matched"] = U[10].udfValue === "CUST_UDF19";
    tests["UDF20 : Matched"] = U[12].udfValue === "CUST_UDF20";
    tests["UDF21 : Matched"] = U[13].udfValue === "CUST_UDF21";
    tests["UDF22 : Matched"] = U[14].udfValue === "CUST_UDF22";
    tests["UDF23 : Matched"] = U[15].udfValue === "CUST_UDF23";
    tests["UDF24 : Matched"] = U[16].udfValue === "CUST_UDF24";
    tests["UDF25 : Matched"] = U[17].udfValue === "CUST_UDF25";
    tests["UDF26 : Matched"] = U[18].udfValue === "CUST_UDF26";
    tests["UDF27 : Matched"] = U[19].udfValue === "CUST_UDF27";
    tests["UDF28 : Matched"] = U[20].udfValue === "CUST_UDF28";
    tests["UDF29 : Matched"] = U[21].udfValue === "CUST_UDF29";
    tests["UDF30 : Matched"] = U[23].udfValue === "CUST_UDF30";
    tests["UDF31 : Matched"] = U[24].udfValue === "CUST_UDF31";
    tests["UDF32 : Matched"] = U[25].udfValue === "CUST_UDF32";
    tests["UDF33 : Matched"] = U[26].udfValue === "CUST_UDF33";
    tests["UDF34 : Matched"] = U[27].udfValue === "CUST_UDF34";
    tests["UDF35 : Matched"] = U[28].udfValue === "CUST_UDF35";
    tests["UDF36 : Matched"] = U[29].udfValue === "CUST_UDF36";
    tests["UDF37 : Matched"] = U[30].udfValue === "CUST_UDF37";
    tests["UDF38 : Matched"] = U[31].udfValue === "CUST_UDF38";
    tests["UDF39 : Matched"] = U[32].udfValue === "CUST_UDF39";
    tests["UDF40 : Matched"] = U[34].udfValue === "CUST_UDF40";
    tests["UDF41 : Matched"] = U[35].udfValue === "CUST_UDF41";
    tests["UDF42 : Matched"] = U[36].udfValue === "CUST_UDF42";
    tests["UDF43 : Matched"] = U[37].udfValue === "CUST_UDF43";
    tests["UDF44 : Matched"] = U[38].udfValue === "CUST_UDF44";
    tests["UDF45 : Matched"] = U[39].udfValue === "CUST_UDF45";
    tests["UDF46 : Matched"] = U[40].udfValue === "CUST_UDF46";
    tests["UDF47 : Matched"] = U[41].udfValue === "CUST_UDF47";
    tests["UDF48 : Matched"] = U[42].udfValue === "CUST_UDF48";
    tests["UDF49 : Matched"] = U[43].udfValue === "CUST_UDF49";
    tests["UDF50 : Matched"] = U[45].udfValue === "CUST_UDF50";

Open in new window

The tests are written in javascript.
I want to replicate this using only a for loop but I don't think a simple loop will work because CUST_UDF10 = U[1] & CUST_UDF2 = U[11];
If I sort the array U, that gives me issues with CUST_UDF1, CUST_UDF10, and CUST_UDF32.

What am I doing wrong here?

    U.sort();
    for(i=0;i<50;i++) {
        x = i+1;
        tests["UDF"+x+"  : Matched"] = U[i].udfValue === "CUST_UDF"+x;
    }

Open in new window

ASKER CERTIFIED SOLUTION
Kelvin McDaniel
Independent Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 4 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 4 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004