There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer audio black screen blue screen boot computer connection crash css dell driver drivers email error ethernet excel explorer firefox firefox 3 hard drive internet internet explorer itunes laptop linux malware monitor network networking nvidia outlook outlook 2003 outlook express password printer problem ram router security slow software sound trojan usb virus vista windows windows vista windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Solved: JS string array assignment question


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
nj2b's Avatar
Junior Member with 20 posts.
 
Join Date: Sep 2006
Experience: Beginner
20-Jul-2008, 11:04 PM #1
Solved: JS string array assignment question
Is there a way in javascript to set a single character within an array of strings without having to create temp variables or slice it? What I have is an array that represents a given image for each character within the string.

for example

Code:
var map = new array("00000000",
                    "10220110",
                    "00220020");


if(x == 2 && y == 4) { map[x].charAt(4) = "9"; }
Unfortunately, I found out the charAt is a read property and the above generates the left-hand assignment error. I was hoping that the replace method would work, but I couldn't figure out how to position it to the desired character. It did replace an occurrence of the character... just not the right one. :P

Any ideas on how to achieve this dynamically using only the array itself?

TIA.
MMJ's Avatar
MMJ MMJ is online now
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
22-Jul-2008, 07:06 AM #2
1. The only argument Array takes is how much you want the length of the array to be.

2. Its possible using indexOf and substr.
nj2b's Avatar
Junior Member with 20 posts.
 
Join Date: Sep 2006
Experience: Beginner
24-Jul-2008, 02:23 AM #3
slicing worked ok for what I wound up settling on, but charAt would have been perfect had it been designed with assignment in mind. I *think* replace may also work provided the position within the string could be set.

Thanks for interest in my question.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:06 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.