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
2 1000 b1randon 171
Recognized Expert New Member -
var arr = new Array( 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1 );
-
var arr2 = new Array();
-
for (var i=0; i<arr.length; i++){
-
if(arr[i]==1)
-
arr2.push(i+1);
-
}
-
for (var i=0; i<arr2.length; i++){
-
alert(arr2[i]);
-
}
-
Should do ya.
Cheers, just the job.
thanks v much
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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'...)
|
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...
|
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,'@','@','@',...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |