Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

findIndex Usage for the Array

former_member492955
Participant
0 Likes
2,809

There is an array :

Array: this.getView().getModel("objects").getProperty("/developmentObjects")

I want to find the index in the array, but there are two parameters that should be equal:

Array.findIndex( developmentObject => (developmentObject.microserviceId == microserviceId && developmentObject.objectName == objectName));

The microserviceId and the objectName should bot fulfill the value.

From my coding, the return value is -1.

But this development object is really in the table

How can I change the sentence?

1 ACCEPTED SOLUTION
Read only

cris_hansen
Product and Topic Expert
Product and Topic Expert
0 Likes
2,382

Dear Bella,

Maybe you can check this page for an working example.

This tutorial might help too.

I also would debug the code or use the console to find the values being evaluated by findIndex and see why the result is -1.

Kind regards,

Cris

5 REPLIES 5
Read only

cris_hansen
Product and Topic Expert
Product and Topic Expert
0 Likes
2,383

Dear Bella,

Maybe you can check this page for an working example.

This tutorial might help too.

I also would debug the code or use the console to find the values being evaluated by findIndex and see why the result is -1.

Kind regards,

Cris

Read only

0 Likes
2,382

Dear cristiano.hansenn

Thanks for your reply, I checked the page, but all the example provide only one parameter.

It is ok for my example if I only set one parameter:

Array.findIndex( developmentObject => developmentObject.uuid == uuid );

But when I change it to fulfill two conditions, then the result will be -1 for my example:

Array.findIndex( developmentObject => (developmentObject.microserviceId == microserviceId && developmentObject.objectName == objectName));

I can find the object in the array, but the findindex result is -1, I think maybe I have some syntax error.

Read only

cris_hansen
Product and Topic Expert
Product and Topic Expert
2,382

Dear Bella,

Have you tried:

Array.findIndex( developmentObject => ((developmentObject.microserviceId == microserviceId) && (developmentObject.objectName == objectName)));

?

Maybe you can print the values, just to be sure that the values are the expected ones.

I'll see whether I find an example with two conditions.

Regards,

Cris

Read only

2,382

Dear cristiano.hansenn,

I found my function is correct, there is only incorrect objectName in my functtion,

Array.findIndex( developmentObject => (developmentObject.microserviceId == microserviceId && developmentObject.objectName == objectName));

Thanks

Read only

catano
Active Participant
0 Likes
2,382

Hi bella.fang,

Could you please share example data of your model (without sensitive information)?

Especially the developmentObjects part.

The syntax you are using is correct: Arrow function expressions - JavaScript | MDN

Regards,

Peter