Arrays Of Arrays...

Oct 5, 2005

Is what I'm doing the right approach to creating an array of arrays? I have an external datafile with several employees' records. They are stored in an array with each element of the array being the complete employee record, ie: name, date of hire, etc., etc. These attributes are delimited by a :. I'm trying to separate these attributes while keeping the original array intact. That way I can access these attributes and validate whether or not an instance of the employee object will occur. There are too many records to create this from the start, so I'm trying to implement a for loop to do it for me. This is what I tried: datafile is the name of the original array of employees. emp is the array I'm trying to create .

for(var i=0;i<datafile.length;i++){
var emp = datafile[i].split(":");
//document.writeln(emp.length+"<br>");
/document.writeln(datafile[i]+"<br>");
}
//document.writeln(datafile[0]+"<br>");

View 4 Replies


ADVERTISEMENT

Arrays And IE

Jul 23, 2005

I've noticed that IE apparently has a horrible implementation of the
array object, since traversing one with as few as 1000 items it tends
to pop up a dialog informing the user that the script is taking too
long. I tried splitting the array into a 10x100 two-dimensional array
as well as changing the array to a linked list, but neither improved
the code's efficiency sufficiently. Can anyone suggest methods for
optimizing array efficiency, or some other workaround for yet another
one of Bill Gates' blunders?

View 13 Replies View Related

Xml Vs Arrays

Jul 23, 2005

I have a web document created by a script and instead of going back to
the db I choose to either create an array to iterate through or xml to
parse through.

So, my question is: What are the trade offs between using an array to
load data from or an xml structure?

My array would look like:

myarray = [[],[],[],[]]

My xml like:

<xml>
<data>
<a></a><b></b>
</data>
</xml>

I would use js to iterate or getElementByTagName to find data. I am thinking the page would load faster using xml, and then the user may not even use that functionality. In all cases I have to load the array to memory.

View 5 Replies View Related

Arrays Different In IE And Others?

May 23, 2007

I am with XHTML and CSS as much do I have to learn in JavaScript programming. I’m just beginning to understand and modify the DOM and I ran into something that I couldn’t find a solution for after some extensive search. I have this function:

if(document.getElementById && document.createElement) {
function addflags() {
var children = document.getElementById('pagelist').childNodes;
for(var i = 0; i < children.length; i++) {
children[0].className = 'bulgaria'
children[1].className = 'england'
children[2].className = 'italy'
children[3].className = 'sweden'
}
}
window.
}


The XHTML is an unordered list with 4 list items and sub lists in those list items (plus links in each li) and I want to add a country flag (set as background image in the CSS) to the direct children of the ul (the first level list items).

Now I discovered that Firefox is only reacting to odd array numbers, i.e. children[1], 3, 5, and 7 (the even numbers have "no properties") while IE is applying the classes correctly(?) as intended above (0,1,2,3).

At which point did I go wrong? Sorry if this is a real stupid question but I’m pretty new in this field and my researches didn’t bring any acceptable results.

View 6 Replies View Related

Arrays And Selects

Jul 23, 2005

How do I set this to "disabled":

<select name="awards[]" multiple size="6">
<option value="1">Award 1</option>
<option value="2">Award 2</option>
<option value="3">Award 3</option>
<option value="4">Award 4</option>
</select>

I don't know how many options there will be as they are fed from a DB.

View 2 Replies View Related

Suggestions About Using Two Arrays

Nov 23, 2005

Anybody got any suggestions about using two arrays. First i need to
ask the user their name and if their require a seat between 1and 5 or
between 6 and 10. I need to assign this information in two arrays.
Any suggestions. I have been working on this so far.
<script type="text/javascript">

var theArray = new Array(10);

//var sizeOfArray = parseInt(prompt("How many items will the array
have?", ""));

for(i=0; i<10; i++)
{

theArray[i] = prompt( "Please enter your name");
}

for(i=0; i<theArray.length; i++)
{

document.writeln( "theArray[" + i + " ] = " + theArray[i] + "<br />");
}
</script>

View 3 Replies View Related

Calculations With Arrays

Sep 12, 2006

I want to make algorithms that take selections from arrays and put them together in new ways. here is a simple array I set up for notes of a piano keyboard: Code:

View 4 Replies View Related

Strings As Arrays

Mar 6, 2007

Safari and FF seem to allow this:

var wiggy = "ABCD";

ch = wiggy[2]; // ch will contain the character 'C'

however my JS book seems to insist that I do this:

ch = wiggy.charAt(2);

and indeed doesn't appear to mention the first method at all.

Since for my particular purpose I want to treat the string as an array
of single characters, I prefer the first method rather than the second.
Is there any reason not to pursue this approach?

View 6 Replies View Related

Assigning Between Arrays By Value

Jul 20, 2005

Any neat way to copy a snapshot of one array to another?

A normal assignment results in the second array pointing to the first,
with changes to either array affecting both.

As a trivial example:

var a=new Array();
a[0]="zero";
var b=a;
b[1]="one";
alert("a="+a.join("*")+String.fromCharCode(10)+"b="+b.join("*"));

.... this results in a and b being identical two-element arrays.

Is there any easy way to set array (b) to be a copy of (a) BY VALUE -
ie using the contents of (a) as they were at the moment of assignment,
but leaving the two arrays separate so that subsequent changes to one
array does not affect the other?

View 3 Replies View Related

Arrays And Functions

Jul 20, 2005

looking for a way to pass an array to a function.
====================================
<script>
function myfunction(arrayname)
{
document.write("blablabla"+ arrayname[1] +"blablabla");
}
</script>

<html stuff>

<script>
arrayname = new Array("what", "is", "wrong");
myfunction(arrayname);
</script>
====================================

View 1 Replies View Related

How To Add A Method To A Set Of Arrays

May 18, 2011

I'm a newbie of JS and don't know if I have got the right terms in my question. I want to lowercase all the arrays:

<script>
var txt = [
["Cats","Dogs","Rabbits"],
["Fish","Bones","Carrots"]
]
document.write(txt[0][1] + " love eating " + txt[1][1]);

[Code]...

View 9 Replies View Related

Using Arrays As Objects?

Jul 4, 2011

"When we combine FUNCTIONS with OBJECTS we get METHODS". Then he creates an empty ARRAY:

var a = [];

then he uses the "push() method" to add elements to the array.

a.push(1,2,3);

uh, methods are for *objects* right? Yet he is using them on an ARRAY.how an array can magically becomes an object that is manipulated by a "method"?I mean, the array is still an array, no? It never actually becomes an object, right? Yet we still use a *method* to manipulate it. See my conceptual quandry?

View 1 Replies View Related

How To Compare 2 Arrays

Dec 16, 2011

I have 2 arrays and I would like to compare the 2 arrays.If an element in array 1 is NOT in array 2 then I would like to display that element. In this case, I should only display the letter "c" but it doesn't work and I don't know why?

Here's my code:

<html><head>
<script type="text/javascript">
function getValue(id){

[code]....

View 6 Replies View Related

Arrays Vs. Objects

Jun 20, 2007

I recently had a problem where I needed to build up an array of strings, that would be join()ed into a string when the array building was complete. however, each value could only be in the array once.

This was a problem for a few reasons. Once a value has gone into an array the only way to check for it that works cross-platform is to scan the array looking for the value. FireFox has the every() and some() functions but they don't work in anything else.

Using an object to simulate an assocaiative array would allow me to avoid this problem by storing key/values with the keys having the same value as the value I was storing. I could then use the (a in b) construct to check that I had not already added a value.

However, array type methods won't work with objects, so I had no access to size () or join () meaning I'd have to manually build the string by iterating over the object.

My solution was to use an array object, but to store the provided data i nboth the array proper and as a property of the array object.


var myArray = new Array;

function addVal (val)
{
if (!(val in myArray))
{
myArray [val] = 1;
myArray.push (val);
}
}

addVal ('one');
addVal ('two');
addVal ('three');
addVal ('one');
addVal ('two');
addVal ('three');

console.log (myArray.length);
console.log (myArray.join (', '));


This approach does use up more memory but it does give me the advantages of both arrays and objects for little extra work. (if you don't have FireBug then replace console.log with alert)

View 1 Replies View Related

How To Merge Two Arrays

Jul 16, 2010

for example if I have two arrys

arr1[10,20,30]
arr2[40,50,60]

how to merge them to get arr1[10,20,30,40,50,60]

View 4 Replies View Related

Arrays And Objects

Oct 28, 2003

I am dabbling with objects and have successfully created an object with various properties, one of which is an Array, and all is fine. the Question I have is can I make an Array of objects? I have the following object:

dataSeries.Type = value
dataSeries.Name = value
dataSeries.dataPoints[n] = Array of values
dataSeries.color = value

What I would like to do is have an Array of multiple objects supposedly like:

dataSeries[0].Type = value
dataSeries[1].Name = value
dataSeries[2].dataPoints[n] = Array of values
dataSeries[3].color = value

Is this possible?

View 2 Replies View Related

Clearing Arrays On The Fly

Jul 12, 2005

Have an array l am building up during end user selections. There is an option to clear all selections, how do l then clear the array?

View 7 Replies View Related

Arrays And Checkboxes

Jul 17, 2006

I have been working on this for the last couple days and have made a lot of headway, but am still stuck on a spot. I have a group of checkboxes on my form that allow the user to select which items apply. I want to verify that at least one checkbox in each group has been selected before allowing them to continue. PHP requires the naming of the arrays to include the [] but jsp (for verification) doesn't like it. I read about and used the .elements method to overcome part of that problem so my for loop is now executing for the number of items in my group:

for (var i=0; i<document.form1.elements['dining_out1[]'].length; i++)

however my if statement won't execute:

if (document.form1.elements['dining_out1[i]'].checked)

even if I have checked ALL checkboxes. I have tried all the different methods I can think of to test for a checked value on each item in the array, but I can't quite figure out what I am missing.

View 2 Replies View Related

Changing Arrays

Aug 17, 2006

How do you change array values based on if..then statements?

if(radioObj[0].checked == true) {
nPrice = new Array ("106.99" , "86.99" , "115.99" , "319.99" )
}
if(radioObj[1].checked == true) {
nPrice = new Array ("89.99" , "74.99" , "102.99" , "239.99" )
}

Specifically, what is wrong with that above?

View 3 Replies View Related

SetTimeout And Arrays

Jun 12, 2007

Basically on the load of a page I am making an ajax call that returns a string with integers seperated by commas. I have verified that the returns from the ajax call are working correctly, but then I am trying to take that string, break it into an array, and use the values in that array to use setTimeout and call the function at those intervals.

//Create our array outside of a function so it's available
var wait_time = new Array();

//function that handles the ajax return
function process_wait_time_return(str)
{
wait_time = str.responseText.split(',');
update_current_show(0, wait_time);
}

//Function that changes the div html with new information
function update_current_show(array_index, wait_time)
{
$("currently_playing").innerHTML = array_index;
var next_index = array_index + 1;
setTimeout('update_current_show(next_index, wait_time)', 3);
}

This is on a test page, so for testing purposes I'm just updating the div with the current array index to verify it's cycling through the array, which it's not.

View 7 Replies View Related

Nested Or Multidimensional Arrays

Jul 23, 2005

I can't figure out why this doesn't work:

---------------------------------------------
greeting = new Array();

greeting[0][0] = "hey";
greeting[0][1] = "bye";


trace(greeting[0][0] + greeting[0][1]);

---------------------------------------------

Shouldn't this automatically create a multidimensional array? Can someone
help me?

View 5 Replies View Related

Form Vbls In Arrays

Jul 23, 2005

I'm working on a page generated by PHP, and all the form fields are named as b[fieldname]. (e.g. <input type=text name='b[name]' value='Adam'>). Javascript seems to barf on this (document.formname.b[name].length is undefined ). Is there any way to get this to work with arrays, or do I just need to use those fields referenced in the js as non-arrays?

View 2 Replies View Related

Associative Multidimensional Arrays

Jul 23, 2005

Is there any way to associate name/value pairs during an array initialization? Like so:

sType = "funFilter"
filterTypeInfo = [];
filterTypeInfo[sType] = new Array("type" : sType);

I can do it using this:

sType = "String"
filterTypeInfo = [];
filterTypeInfo[sType] = [];
filterTypeInfo[sType]["type"] = sType;

but that seems rather cludgy. I want to use array objects not Object objects as described here:

View 8 Replies View Related

Creating Arrays From Strings

Feb 15, 2006

How would I put 2 strings like this into 2 separate arrays like my
examples below?

Div10,Div11|Div2,Div3,Div8,Div4,Div12,Div1,Div5|Di v3,Div5,Div9

France|Germany|Norway

var DivOrder = new
Array("Div10,Div11","Div2,Div3,Div8,Div4,Div12,Div1","Div3,Div5,Div9");
var DivNames = new Array("France", "Germany", "Norway");

View 5 Replies View Related

Session Variables And Arrays

Jun 28, 2007

I had written code which created a shopping cart into an array using
vbscript and then transferred the information into a session
variable. However what I didn't know was that deleting/manipulating
information in an array using vbscript was not that easy.

In doing some reading and research it seemed that js was more flexible
in this area. My questions:

1) if I want to store cart items/details in an array and session
variable do I need to use only js (and can not switch back and forth
from vbscript and js)

2) if I have an array 6x12 and want to delete all the items
associated with say arrayItem[1, 0...12] what is the proper coding to
delete...is it splice?

3) any good articles about js, arrays, and multidimensional arrays
for a beginner?

View 3 Replies View Related

Query On Arrays Of Controls

Jul 20, 2005

It is well-documented that if on a page there are several radio-
buttons with the same name these are addressed as an array (and act
collectively).

Someone (LRN?) recently wrote about another case where name-match
implies array addressing.

It therefore occurred to me to try the following crude Web page:.

View 17 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved