Application Development 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: 

findIndex Usage for the Array

former_member492955
Participant
0 Kudos
862

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

cris_hansen
Advisor
Advisor
0 Kudos
435

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

cris_hansen
Advisor
Advisor
0 Kudos
436

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

0 Kudos
435

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.

435

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

435

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

catano
Participant
0 Kudos
435

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