Wrox Programmer Forums
|
BOOK: Professional JavaScript for Web Developers 3rd edition
This is the forum to discuss the Wrox book Professional JavaScript for Web Developers, 3rd Edition by Nicholas C Zakas; ISBN: 978-1-1180-2669-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional JavaScript for Web Developers 3rd edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 23rd, 2014, 08:45 PM
Registered User
 
Join Date: Sep 2014
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default index method or property

on page 156 at the bottom of the page I am working with this code:

var text = "cat, bat, sat, fat";
var pattern = /.at/;

//same as pattern.exec(text)
var matches = text.match(pattern);
alert(matches.index); // this line here
alert(matches[0]);
alert(pattern.lastIndex);

I had a question about the .index above.
Here "matches" appears to be a string (if there is only one match returned).
When I changed pattern to be "/.at/g" then multiple strings are returned and then I can access matches[1] which is "bat".

However in that case matches.index returns undefined instead of 0.

As an aside I do not know why the author included the last alert.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Doesn't support property or method ayazhoda Access VBA 2 November 16th, 2009 07:35 AM
OBJECT DOESNT SUPPORT THIS PROPERTY OR METHOD KGANESH2006 Classic ASP Basics 4 March 24th, 2006 11:15 AM
Object doesn't support this property or method ASP crmpicco Classic ASP Components 0 March 16th, 2006 01:26 PM
Property/Method access using string values jaucourt VB.NET 2002/2003 Basics 1 February 10th, 2004 01:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.