473,503 Members | 3,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Array Positions Into An Array

27 New Member
Hi,

I have an array:

( 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, )

and i need to find the positions of the 1's and place those positions into another array, eg.-

( 2, 7, 11, 12, )

Any ideas.

cheers
Dec 12 '06 #1
2 1000
b1randon
171 Recognized Expert New Member
Expand|Select|Wrap|Line Numbers
  1. var arr = new Array( 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1 );
  2. var arr2 = new Array();
  3. for (var i=0; i<arr.length; i++){
  4.     if(arr[i]==1)
  5.         arr2.push(i+1);
  6. }
  7. for (var i=0; i<arr2.length; i++){
  8.     alert(arr2[i]);
  9. }
  10.  
Should do ya.
Dec 12 '06 #2
adz1809
27 New Member
Cheers, just the job.

thanks v much
Dec 12 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3928
by: ChronoFish | last post by:
Hi there, I want to iterate through an array starting at a known index. However the indexes are not linear. For example I have an array of events keyed by timestamp. $eventList = array...
9
1291
by: mps | last post by:
Suppose..... arr = Array("only","a","test"); ArrayVar = "arr"; alert(ArrayVar); This the simplyfied version of my problem.. (alerting 'undefined' instead of 'only'...)
6
1209
by: Abby Lee | last post by:
I've created the following array and want to be able to process each indivisual object whenever my function is called. Is this best done with a "foreach"? I don't see a foreach in my javascript...
6
3614
by: Anjali | last post by:
Hi, I am handling an array with a hexadecimal index for the first time. What actually does the below means. arr = { '@','£','$','@','@','@','@','@','@','@', 10,'@', 13,'@','@','@',...
21
3168
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.