0

I have an Array of Array:

val arr = Array(Array("1","page"),Array("1","thankyou"))

I know that indexOf function is used to get the first index of an element in an array but not sure how to get the index of outer array based on inner array elements. Like index of "page" in arr is 0 and index of "thankyou" is 1. Kindly suggest a solution in Scala.

Thanks

1 Answer 1

3

Try

arr.map(_.indexOf("page"))     // 1, -1
arr.map(_.indexOf("thankyou")) // -1, 1

for the indexes in inner arrays (-1 means "not found") and

arr.indexWhere(_.exists(_ == "page"))     // 0
arr.indexWhere(_.exists(_ == "thankyou")) // 1

for the index in an outer array.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.