473,835 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing an array value to upper case?

I tried using the "toUpperCas e()" property to change the value of an array
entity to uppercase BUT it tells me that the property is invalid. It seems
that an array is not considered an object when it is assigned a text
literal?? HOW can I change the array value to upper case then? What other
method exists for arrays?

Ex:
var GridArrayName1 = new Array();
GridArrayName1[0] = new Array ('test-value');
GridArrayName1[0] = GridArrayName1[0] .toUpperCase();

The above won't work. I even tried assigning it to an object then using the
object's "toUpperCase()" , but after the assignment the object now longer has
that property either??

'Sup?

thx,

--
=============== =============== =============== ====
Mike S. Nowostawsky:
Email: mi******@sympat ico.ca, mi******@yahoo. ca
Home Page: http://www3.sympatico.ca/mikenowo/
Lachine (Montreal), Quebec, Canada
Jul 20 '05 #1
8 10235
>It seems that an array is not considered an object when it is assigned a text
literal?? HOW can I change the array value to upper case then? What other
method exists for arrays?

Ex:
var GridArrayName1 = new Array();
GridArrayName1[0] = new Array ('test-value');
GridArrayName1[0] = GridArrayName1[0] .toUpperCase();

The above won't work. I even tried assigning it to an object then using the
object's "toUpperCase()" , but after the assignment the object now longer has
that property either??


The Array object does not contain the .toUpperCase() method.

In line two, you created a two-dimensional array when you
assigned new Array( 'test-value') to GridArrayName1[0]. You
attempted to use the .toUpperCase() method on this Array object.
You need to take this second dimension array into account..

var GridArrayName1 = new Array();
GridArrayName1[0] = new Array( "test-value");
GridArrayName1[0][0] = GridArrayName1[0][0].toUpperCase();

Peace, Vm
Yaz

Providing complicated solutions to simple problems since 1997.
Jul 20 '05 #2
Lee
Mike S. Nowostawsky said:

I tried using the "toUpperCas e()" property to change the value of an array
entity to uppercase BUT it tells me that the property is invalid. It seems
that an array is not considered an object when it is assigned a text
literal?? HOW can I change the array value to upper case then? What other
method exists for arrays?

Ex:
var GridArrayName1 = new Array();
GridArrayName1[0] = new Array ('test-value');
GridArrayName1[0] = GridArrayName1[0] .toUpperCase();

The above won't work. I even tried assigning it to an object then using the
object's "toUpperCase()" , but after the assignment the object now longer has
that property either??


You seem to be confused about the difference between an Array and
an element of an Array. You can't assign a text literal to an Array.
You assign values to array elements. Array elements can be any type.

Your second assignment creates a new Array containing one string
element and makes that array the first element of GridArrayName1.
You would access that string element as GridArrayName1[0][0].

If you want to assign the string literal value to the first
element of GridArrayName1, you should use:
GridArrayName1[0] = "test-value";

Jul 20 '05 #3
JRS: In article <XL************ ******@news20.b ellglobal.com>, seen in
news:comp.lang. javascript, Mike S. Nowostawsky <mi******@sympa tico.ca>
posted at Sun, 28 Dec 2003 15:08:45 :-
I tried using the "toUpperCas e()" property to change the value of an array
entity to uppercase BUT it tells me that the property is invalid. It seems
that an array is not considered an object when it is assigned a text
literal?? HOW can I change the array value to upper case then? What other
method exists for arrays?

Ex:
var GridArrayName1 = new Array();
GridArrayName1[0] = new Array ('test-value');
GridArrayName1[0] = GridArrayName1[0] .toUpperCase();

The above won't work. I even tried assigning it to an object then using the
object's "toUpperCase()" , but after the assignment the object now longer has
that property either??

By using the second new Array, you put an Array in the first Array. It
is then GridArrayName1[0][0] that holds 'test-value', as shown by

var GridArrayName1 = new Array();
GridArrayName1[0] = new Array ('test-value');
GridArrayName1[0] = GridArrayName1[0][0] .toUpperCase();

But what you should be writing is

var GridArrayName1 = new Array();
GridArrayName1[0] = 'test-value'
GridArrayName1[0] = GridArrayName1[0].toUpperCase();

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #4
Thanks very much all 3 of you for that explanation. I now understand what
the problem was. I'm used to creating multiple dimensional arrays in a
different fashion. In this case I only want a single dimension, so your
suggestion of "GridArrayN ame1[0] = 'test-value';" does the trick. See what
happens when you try to modify other peoples' code without actually knowing
their initial intentions! <chuckle>

Thx again!

--
=============== =============== =============== ====
Mike S. Nowostawsky:
Email: mi******@sympat ico.ca, mi******@yahoo. ca
Home Page: http://www3.sympatico.ca/mikenowo/
Lachine (Montreal), Quebec, Canada
"Mike S. Nowostawsky" <mi******@sympa tico.ca> wrote in message
news:XL******** **********@news 20.bellglobal.c om...
I tried using the "toUpperCas e()" property to change the value of an array
entity to uppercase BUT it tells me that the property is invalid. It seems
that an array is not considered an object when it is assigned a text
literal?? HOW can I change the array value to upper case then? What other
method exists for arrays?

Ex:
var GridArrayName1 = new Array();
GridArrayName1[0] = new Array ('test-value');
GridArrayName1[0] = GridArrayName1[0] .toUpperCase();

The above won't work. I even tried assigning it to an object then using the object's "toUpperCase()" , but after the assignment the object now longer has that property either??

'Sup?

thx,

--
=============== =============== =============== ====
Mike S. Nowostawsky:
Email: mi******@sympat ico.ca, mi******@yahoo. ca
Home Page: http://www3.sympatico.ca/mikenowo/
Lachine (Montreal), Quebec, Canada

Jul 20 '05 #5
Now, my last step was to read data values from a text file instead of
imbedding them in the html itself (i.e. read each line and assign it to the
next value in the array). Can this be done in javascript? I've done it with
VB and countless other languages, but don't know if javascript is that
versatile.

Thx,
--
=============== =============== =============== ====
Mike S. Nowostawsky:
Email: mi******@sympat ico.ca, mi******@yahoo. ca
Home Page: http://www3.sympatico.ca/mikenowo/
Lachine (Montreal), Quebec, Canada
"Mike S. Nowostawsky" <mi******@sympa tico.ca> wrote in message
news:XL******** **********@news 20.bellglobal.c om...
I tried using the "toUpperCas e()" property to change the value of an array
entity to uppercase BUT it tells me that the property is invalid. It seems
that an array is not considered an object when it is assigned a text
literal?? HOW can I change the array value to upper case then? What other
method exists for arrays?

Ex:
var GridArrayName1 = new Array();
GridArrayName1[0] = new Array ('test-value');
GridArrayName1[0] = GridArrayName1[0] .toUpperCase();

The above won't work. I even tried assigning it to an object then using the object's "toUpperCase()" , but after the assignment the object now longer has that property either??

'Sup?

thx,

--
=============== =============== =============== ====
Mike S. Nowostawsky:
Email: mi******@sympat ico.ca, mi******@yahoo. ca
Home Page: http://www3.sympatico.ca/mikenowo/
Lachine (Montreal), Quebec, Canada

Jul 20 '05 #6
Yes, you can use server-side javascript (like ASP) to read the
textfile line by line and assign the cintent to your array.
But this is server-side only.
Do you have access?

Kien
"Mike S. Nowostawsky" <mi******@sympa tico.ca> wrote in message news:<pC******* ************@ne ws20.bellglobal .com>...
Now, my last step was to read data values from a text file instead of
imbedding them in the html itself (i.e. read each line and assign it to the
next value in the array). Can this be done in javascript? I've done it with
VB and countless other languages, but don't know if javascript is that
versatile.

Thx,
--

Jul 20 '05 #7
Mike S. Nowostawsky wrote:
I tried using the "toUpperCas e()" property to change the value of an array
entity to uppercase BUT it tells me that the property is invalid. It seems
that an array is not considered an object when it is assigned a text
literal??
An array cannot be assigned a "text literal" (better: string literal)[1]
for it has no real value.[2] What you have done by using the
Array(...) constructor is assigning a value to an *element* of the array
(the first one, to be precise). A special context is required to
convert the array's "value" (see above) to a String object. Such
contexts are for example the alert(...) method call or the (String)
concatenation operation with "+". But note that the toString() method
is implemented different in different hosts, so do not count on that it
returns a comma-separated list of the elements' values or so.
OW can I change the array value to upper case then?
Again, an array (here: Array object) does not have a value (at least
none that you can actually *write* to). I presume you meant: How can
I change the string value of all array elements to uppercase?

One is to convert the Array object to a String object (e.g. using
the Array.join(...) method), uppercase that String (e.g. using its
toUpperCase(... ) method) and split it into array elements again
(e.g. using its split(...) method). Another is to iterate the array
elements and uppercase each element. While the former is presumably
faster, the latter is more reliable as it does not split substrings
separated by delimiters in element values to different array elements.
What other method exists for arrays?
RTFM:

http://devedge.netscape.com/library/...nce/array.html
Ex:
var GridArrayName1 = new Array();
GridArrayName1[0] = new Array ('test-value');
GridArrayName1[0] = GridArrayName1[0] .toUpperCase();

The above won't work.
BAD. Borken as designed. Maybe you did not want a
*two-dimensional* array (because that is what you did)
but only

var GridArrayName1 = new Array();
GridArrayName1[0] = 'test-value';
GridArrayName1[0] = GridArrayName1[0].toUpperCase();

which could be shortened to either

var GridArrayName1 = new Array('test-value');
GridArrayName1[0] = GridArrayName1[0].toUpperCase();

as well as to

var GridArrayName1 = ['test-value'];
GridArrayName1[0] = GridArrayName1[0].toUpperCase();

or

var GridArrayName1 = new Array();
GridArrayName1[0] = 'test-value'.toUpperC ase();

as well as to

var GridArrayName1 = [];
GridArrayName1[0] = 'test-value'.toUpperC ase();
I even tried assigning it to an object then using the
object's "toUpperCase()" , but after the assignment the
object now longer has that property either??
toUpperCase() is a native method of
String objects, not of Array objects.

However, if you need it, you can add a method
with that identifier to the Array prototype:

function array_toUpperCa se(/** @optional Array */ a)
/**
* Takes input array <code>a</code> or the Array object
* it is applied to as method and returns a new Array
* object with all elements in uppercase. Elements that
* were previously not string values are automagically
* converted to String.
*
* @author
* (C) 2004 Thomas Lahn &lt;ar******@Po intedEars.de&gt ;
* @partof
* http://pointedears.de.vu/scripts/array.js
* @requires
* types#isArray()
* @param a
* Array which elements should be converted.
* Is used instead of the Array object the
* function is applied to.
* @returns
* A copy of <code>a</code> or the Array object with its
* elements' value in uppercase. If <code>a</code> has no
* elements, an empty array is returned.
* @see
* http://pointedears.de.vu/scripts/JSDoc/
*/
{
if (!a && isArray(this))
{
a = this;
}

if (isArray(a))
{
for (var i = 0; i < a.length; i++)
{
a[i] = String(a[i]).toUpperCase() ;
}
return a;
}
else
{
return new Array();
}
}
Array.prototype .toUpperCase = array_toUpperCa se;
'Sup?


?
PointedEars
___________
[1] A *reference* to an Array object can of course be assigned a String
literal, but then it will not reference that Array object anymore.

[2] What its valueOf(...) method yields is only the result of its
toString(...) method. When assigning another value, including
another Array object/literal to its reference, the previous Array
object is preserved (until it is garbage-collected) but becomes
unavailable if there is no other reference to it.
Jul 20 '05 #8
Mike S. Nowostawsky wrote:
I tried using the "toUpperCas e()" property to change the value of an array
entity to uppercase BUT it tells me that the property is invalid. It seems
that an array is not considered an object when it is assigned a text
literal??
An array cannot be assigned a "text literal" (better: string literal)[1]
for it has no real value.[2] What you have done by using the
Array(...) constructor is assigning a value to an *element* of the array
(the first one, to be precise). A special context is required to
convert the array's "value" (see above) to a String object. Such
contexts are for example the alert(...) method call or the (String)
concatenation operation with "+". But note that the toString() method
is implemented different in different hosts, so do not count on that it
returns a comma-separated list of the elements' values or so.
OW can I change the array value to upper case then?
Again, an array (here: Array object) does not have a value (at least
none that you can actually *write* to). I presume you meant: How can
I change the string value of all array elements to uppercase?

One is to convert the Array object to a String object (e.g. using
the Array.join(...) method), uppercase that String (e.g. using its
toUpperCase(... ) method) and split it into array elements again
(e.g. using its split(...) method). Another is to iterate the array
elements and uppercase each element. While the former is presumably
faster, the latter is more reliable as it does not split substrings
separated by delimiters in element values to separate array elements.
What other method exists for arrays?
RTFM:

http://devedge.netscape.com/library/...nce/array.html
Ex:
var GridArrayName1 = new Array();
GridArrayName1[0] = new Array ('test-value');
GridArrayName1[0] = GridArrayName1[0] .toUpperCase();

The above won't work.
BAD. Borken as designed. Maybe you did not want a
*two-dimensional* array (because that is what you did)
but only

var GridArrayName1 = new Array();
GridArrayName1[0] = 'test-value';
GridArrayName1[0] = GridArrayName1[0].toUpperCase();

which could be shortened to either

var GridArrayName1 = new Array('test-value');
GridArrayName1[0] = GridArrayName1[0].toUpperCase();

as well as to

var GridArrayName1 = ['test-value'];
GridArrayName1[0] = GridArrayName1[0].toUpperCase();

or

var GridArrayName1 = new Array();
GridArrayName1[0] = 'test-value'.toUpperC ase();

as well as to

var GridArrayName1 = [];
GridArrayName1[0] = 'test-value'.toUpperC ase();
I even tried assigning it to an object then using the
object's "toUpperCase()" , but after the assignment the
object now longer has that property either??
toUpperCase() is a native method of
String objects, not of Array objects.

However, if you require it, you could add a method with that identifier
to the Array prototype:

function array_toUpperCa se(/** @optional Array */ a)
/**
* Takes input array <code>a</code> or the Array object
* it is applied to as method and returns a new Array
* object with all elements in uppercase. Elements that
* were previously no string values are automagically
* converted to String.
*
* @author
* (C) 2004 Thomas Lahn &lt;ar******@Po intedEars.de&gt ;
* @partof
* http://pointedears.de.vu/scripts/array.js
* @requires
* types#isArray()
* @param a
* Array which elements should be converted.
* Is used instead of the Array object the
* function is applied to.
* @returns
* A copy of <code>a</code> or the Array object with its
* elements' value in uppercase. If <code>a</code> has no
* elements, an empty array is returned.
*/
{
if (!a && isArray(this))
{
a = this;
}

if (isArray(a))
{
for (var i = 0; i < a.length; i++)
{
a[i] = String(a[i]).toUpperCase() ;
}
return a;
}
else
{
return new Array();
}
}
Array.prototype .toUpperCase = array_toUpperCa se;
'Sup?


?
PointedEars
___________
[1] A *reference* to an Array object can of course be assigned a String
literal, but then it will not reference that Array object anymore.

[2] What its valueOf(...) method yields is only the result of its
toString(...) method. When assigning another value, including
another Array object/literal to its reference, the previous Array
object is preserved (until it is garbage-collected) but becomes
unavailable.
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2966
by: Stephen Williams | last post by:
Hey i've got bunch of arrays of tick boxes, each array contains somewhere between 5 and 20. What I want to do is write a function that returns the captions of every ticked tick box in an array as a string. I want to be able to pass to the function the array name, and the lower and upper limits of the array. But I have no idea how to pass the control name (array name).
10
2431
by: Tom | last post by:
Hi I am looking for an optimal data-structure in order to replace a map<int,float>. I use it as some kind of sparse array representation. The facts: - the population in the data-structures can be bigger than 10^6 - the maximum number of elements (upper bound) is known and fixed - the key is an integer, the element is a float value
1
2205
by: aemazing | last post by:
i've been tryin to do the following - -Add a new flight number to the end of the queue (got it done) -LAnd the plane at the front of the queue - problems wit it- -display the queue - got it done -seach for a specific flight number in queue ( didn't get there yet) -move a flight number one one position in the queue to another ( didn't get there yet) this is what i have so far. it runs but something is wrong and i don't know what it is.
46
3263
by: RoSsIaCrIiLoIA | last post by:
Write a function that gets an array of unsigned int fill it with random values all differents, and sorts it. It should be faster than qsort too. Do you like my solution? _______________________ #include <stdio.h> #include <stdlib.h> #include <time.h>
204
13149
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 = {0,1,2,4,9};
1
4110
by: Firewalker | last post by:
I am attempting to change the backColor property on the previously instantiated buttons FROM a listbox_doubleClick event. I thought it would be something like this: If Me.Controls.Item(iSeatNumber).BackColor.Equals(Color.White) Then Me.Controls.Item(iSeatNumber).BackColor.Equals(Color.CornflowerBlue) 'End If
104
17030
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from that array Could you show me a little example how to do this? Thanks.
10
12221
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to help do the most basic things. One of the "basic" things I haven't been able to find out how to do is how to delete an item from a multidimensional array object and resize it afterwards. It seems so easy to conceive of the code to delete...
6
2097
by: Jeff | last post by:
I'd like to have a default array as a function parameter. I can do this: function my_function($MY_ARRAY = array('1'=>'one')){... But not this: function my_function($MY_ARRAY = $_POST){...
0
9653
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10562
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10236
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6968
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5639
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3997
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3092
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.