Any alternate of if-else/Switch statement

Hi Team, I need to verify response based on the certain conditions. Yes I can verify through if/else or switch statement but there is any other way to verify such responses.

“rank”: {
“id”: 110,
“description”: “Director”

Now here we have 50 ids and based on that different description since if/else and switch statement making code more lengthy, Any other solution?

Let me know if need more info.

Hey @aakashjain8693 :wave:

I understand you want to verify “description” in the response based on its “id” value.
In that case, maybe you can define a dictionary (object) linking id value and description (as below) and compare “description” value in the response to that value in dictionary.

const dict = {
    110: 'director', 
    120: 'programmer'

pm.test('Check response value', () => {

Hope this helps!

1 Like

Thanks, Looks perfect!!

Happy to help! :smiling_face_with_three_hearts: