• 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
0
Question by amnakhan786 · Apr 08, 2012 at 07:21 AM · javascriptarrays

how to save an array element in a var or another array element?

Hi, i want to save an array element in a variable or another array element. or do something like the following: i have one array with indexes which is ind[]. another array op with 5 elements. i want to arrange op[] with respect to the indexes given by ind[] such that op[0] is copied oup[4], op[2] is copied to oup[3]. the positions are saved in ind[]. i tried to do it the way it is done in C but it is wrong. since i am a beginner i would really appreciate any help. the code is as follows:

var i; var jt= new Array(); jt[0]=0; var op = new Array(); op[0]=12; op[1]=14; op[2]=5; op[3]=7; op[4]=20; var ind = new Array(); ind[0]=4; ind[1]=1; ind[2]=3; ind[3]=0; ind[4]=2; var oup= new Array(); oup[0]=0; oup[1]=0; oup[2]=0; oup[3]=0; oup[4]=0;

for (i=0;i "); document.write(oup[i] + "
"); document.write("this is op " +op[i] + "
"); document.write("this is index "+ind[i] + "
"); } `

Comment
Add comment · Show 2
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 GuyTidhar · Apr 08, 2012 at 07:30 AM 0
Share

Please use the format button (101010) around the code so it is readable.

avatar image Kleptomaniac · Apr 08, 2012 at 07:35 AM 0
Share

Agreed. Also, never use Arrays. Use Lists. For more info, check here.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Getting C# to access a javascript global Array and Components 1 Answer

How would I call upon an asset in the projects tab with an array? 1 Answer

Remove Items and Item Tooltips 0 Answers

How do I delete the elements in array? 1 Answer

Why does it give me this error and how can i fix it? 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