Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Ilya · Apr 13, 2011 at 10:20 PM · javascriptlist

FindIndex in a List

I need to get an index of an object in List with a certain condition.

class Marker { public var index : int; }

var List.<Marker> allMarkers;

public function GetIndexForMarker (_marker : Marker) : int { return allMarkers.FindIndex(RoadMarker m => m.markerIndex == _marker.markerIndex); //This doesn't work. }

What basically I need to implement is the following, but with FindIndex to make it shorter.

public function GetIndexForMarker (_marker : Marker) : int { var i : int = 0; for (var currentMarker : Marker in allMarkers) { if (currentMarker.index == _marker.index) return i;

 i++;    

} }

How can I use FindIndex in JavaScript?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Bunny83 · Apr 13, 2011 at 10:35 PM

The index you refer to is a variable of your Marker class. So the best way to search a specific number is that you're using in your second example. I don't even think the first one is javascript....

Anyways, if your the index value of your Marker is the same as the index into the List you can just use the IndexOf() method...

int index = allMarkers.IndexOf(marker);


edit

Since i don't have much experience with LINQ and lambda expressions i can't say much about that, but i guess i've found what you're after. According to this question you should look here:
http://unity3d.com/support/documentation/Manual/MonoUpgradeDetails.html

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Apr 13, 2011 at 10:46 PM 0
Share

Your first code looks like a mix of javascript and a bit LINQ to me... LINQ would be another way to do what you want, but i'm not familiar with LINQ ;)

avatar image Ilya · Apr 13, 2011 at 11:17 PM 0
Share

Thanks, that seems to be exactly what I need! :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

A node in a childnode? 1 Answer

Java Script command list 3 Answers

How to make a List Constructor? 1 Answer

Make an array containting multiple classes 1 Answer

Can you define a jagged Generic List in UnityScript? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges