Getting good with javascript

Page 61

61

More Basics

case, substring goes back to the character of that index. For example, Example 3.14 var greeting = "Hello, Andrew, what's up?", name = greeting.substring(13, 7); alert(name); // Andrew

split It’s easy to pull a string into an array with the split method. Just pass the method a parameter determining what character to split the array on. Example 3.15 var arr = "apples oranges peaches bananas".split(" "); console.log(arr); // ["apples", "oranges", "peaches", ▶ "bananas"]

Yes, this is the way lazy programmers create arrays. But it has more use than just as an alternative to an array literal. toLowerCase and toUpperCase I’m sure you know exactly what these do: easy converting of a string to upper- or lowercase: Example 3.16 var usa

= "usa".toUpperCase(),

comment = "THIS MIGHT BE A COMMENT"; comment = comment.substr(0,1) + comment.slice(1).▶ toLowerCase();


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.