JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 29th, 2009, 02:50 PM
roughie roughie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 53 roughie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 11 m 53 sec
Reputation Power: 5
Accessing an array entry's item

I created an array, whose entries looks like this:

[41, "The bird flew into it's cage"]
[33, "He drew fire from Joe"]
[33, "Roger asked her her name"]
[2, "I am awfully happy"]
.

I want to pull the sentence item
out of some array entries.
E.g., in the second entry,
namely, arrayName[1],
what I thought was the
second item (the sentence),
I could manage by invoking
arrayName[1][1].

But to my dismay,
this doesn't do the trick.
arrayName[1][1] actually delivers up
the second CHARACTER of the
entry (the number "3").

I thought the comma between
the number and the sentence would
separate the items, although I
"pushed" each entry into the array
as one single entry.

How do I "grab" the whole sentence?
How do I push both items separately
to achieve "one entry"?

Reply With Quote
  #2  
Old October 29th, 2009, 03:17 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,690 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 3 h 43 m 28 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Sounds like you have an array of
javascript Code:
Original - javascript Code
  1. var arrayName = [
  2.     '[41, "The bird flew into it\'s cage"]',
  3.     '[33, "He drew fire from Joe"]',
  4.     '[33, "Roger asked her her name"]',
  5.     '[2, "I am awfully happy"]'
  6. ];

What's arrayName[1][0]?

Reply With Quote
  #3  
Old October 30th, 2009, 09:58 AM
roughie roughie is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 53 roughie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 11 m 53 sec
Reputation Power: 5
I should have clarified Requinix, I want to
select a few words out of the sentence.
Which means the sentence item of the entry
is itself an array.

I thought, wrongly, that simply
putting square brackets around the sentence
would render the item as an array.

Here's my code, with some calculations
replaced by comments to eliminate overload.
Code:
<script language="javascript">
	jsArray = new Array();
	<?php
		$file = fopen("./phpArray.txt","r");
		$item1 = "";
		$item2 = "";
		$itemEntry = "";
		while(! feof($file))
		{	
			$row = fgets($file);
			// Calculate $digits and $length
			$item1 = substr($row, $digits, $length);
			// Calculate $startat and $len
			$item2 = "'".substr($row, $startat, $len)."'";
			$itemEntry = "[".$item1.",'".$item2."']";
			print "jsArray.push(\"$itemEntry\" );";				
		} 
		fclose($file);
	?>
</script>
I suppose item2 needs to be an array
on its own. How do I change these 3 lines:
$item2 = "";

$itemEntry = "[".$item1.",'".$item2."']";
print "jsArray.push(\"$itemEntry\" );";

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Accessing an array entry's item

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap