JavaScript Strings and Arrays

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Intro to Javascript CS Client Side Scripting CS380 2.
Chapter 41 Variables and JSP Control Structures JavaServer Pages By Xue Bai.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Chapter 7: Working with Arrays
 2004 Prentice Hall, Inc. All rights reserved. Chapter 12 - JavaScript: Objects Outline 12.1 Introduction 12.2 Thinking About Objects 12.3 Math Object.
1.
XP Tutorial 14 New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Scripting Languages.
1 JavaScript: Objects and Object Models October 25, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel,
String Object.  Conundrum: I would like people to have more time on the revisions…  … but I don't have a lot of time myself for more grading  A1 Revision.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
Arrays BCIS 3680 Enterprise Programming. Overview 2  Array terminology  Creating arrays  Declaring and instantiating an array  Assigning value to.
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
BEGINNING MULTIPLICATION BASIC FACTS Multiplication is REPEATED ADDITION. It is a shortcut to skip counting. The first number in the problem tells.
Functions and Arrays. Predefined Functions eval(condition) –Evaluates (executes) JavaScript syntax –Eval returns an undefined value parseInt(string) and.
Project 1: Using Arrays and Manipulating Strings Essentials for Design JavaScript Level Two Michael Brooks.
Chapter 3: Classes and Objects Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved Java’s String Class.
Unit 12 JavaScript Arrays Instructor: Brent Presley.
CSC Programming I Lecture 9 September 11, 2002.
ECA 225 Applied Interactive Programming1 ECA 225 Applied Online Programming strings.
Sahar Mosleh California State University San MarcosPage 1 Object Base Programming.
Computer Programming 2 Lab (1) I.Fatimah Alzahrani.
Lab String Concatenation String s3 = s1.concat(s2); String s3 = s1 + s2; s1 + s2 + s3 + s4 + s5 same as (((s1.concat(s2)).concat(s3)).concat(s4)).concat(s5);
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Chapter 4 Java Script – Part2. 2 Location object Properties Properties href – whole path will be displayed. ex: window.location.href ( see example 11)
Chapter 5 Arrays F Introducing Arrays F Declaring Array Variables, Creating Arrays, and Initializing Arrays F Passing Arrays to Methods F Copying Arrays.
Java Script: Objects (Chapter 12 in [2]). 2 Outline Introduction Introduction Thinking About Objects Thinking About Objects Math Object Math Object String.
ARRAYS (Extra slides) Arrays are objects that help us organize large amounts of information.
Applied Component I Unit II Introduction of java-script
Computer Programming ||
Chapter 7: Working with Arrays
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
SEEM4570 Tutorial 05: JavaScript as OOP
Chapter 5: Arrays: Lists and Tables
The relational operators
Visual Basic .NET BASICS
String, Math & Miscellaneous Methods & Properties
© Akhilesh Bajaj, All rights reserved.
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Tonga Institute of Higher Education
Arrays 6-Dec-18.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
Data Structures and Database Applications Arrays And Lists
PERL: part II hashes, foreach control statements, and the split function By: Kevin Walton.
Functions, Regular expressions and Events
JavaScript Arrays.
16 Strings.
Compiler Design Second Lecture.
Array?.
Variables Kevin Harville.
M150: Data, Computing and Information
Given value and sorted array, find index.
Microsoft Visual Basic 2005: Reloaded Second Edition
Graphics Considerations
Recognizing JavaScript Features
String Processing 1 MIS 3406 Department of MIS Fox School of Business
String Processing 1 MIS 3406 Department of MIS Fox School of Business
String methods 26-Apr-19.
Visual Programming COMP-315
Javascript data structures
Arrays 2-May-19.
Exam Prep.
CIS 136 Building Mobile Apps
String, Math & Miscellaneous Methods & Properties
What is a String? String s = "compsci"; s c o m p s i
Arrays.
Unit-2 Objects and Classes
What We Want To Do User enters: Mary Smith
Presentation transcript:

JavaScript Strings and Arrays Kevin Harville

Strings and Arrays Strings are indexed groups of CHARACTERS. Arrays are indexed groups of numbers. Therefore we can refer to a particular number or letter by referring to its index.

Array Examples I could have an array of images: myImage[1] = “myDog.jpg” myImage[2] = “myCat.jpg” myImage[3] = “myFish.jpg” Or an array of the students’ scores: classScore[0] = 100 classScore[1] = 95 classScore[2] = 86

Strings and Arrays Strings and Arrays are objects rather than variables. Objects have properties and methods myString = “Kevin” makes it look like a variable, but is actually a shortcut to make strings easy to use. IMPORTANT: Strings and Arrays are indexed, or counted, starting at 0, not 1.

String Properties myString.length

String Methods String objects have several useful methods: myString.toLowerCase(); myString.toUpperCase(); Others Follow…

String Methods: Substring myString.substring(start, end+1); “Kevin”.substring(0,2) returns “Ke” “Kevin”.substring(1,3) returns “ev” REMEMBER: ARRAYS START AT ZERO!

String Methods: charAt charAt returns the value of the character at an index position: “Kevin”.charAt(4) returns “n” why “n”?

String Methods: indexOf “Kevin”.indexOf(“vi”) returns 2 indexOf returns –1 if it is not found: Kevin.indexOf(“Joe”) returns –1 You can specify the starting position: “Rin Tin Tin”. indexOf(“in”, 4) returns 5 To find multiple occurrences repeat the process.

String Methods: lastIndexOf Same as indexOf, but starts searching from the end.

String Methods: Split This method creates an array myNewStrings = “Quick Brown Fox”.Split(“ “); myNewStrings[0] = “Quick” myNewStrings[1] = “Brown” myNewStrings[2] = “Fox”

Some Other String Methods: .replace (4.0 Browsers or higher) HTML functionality, such as .fontcolor .fontsize .strike .etc.

Arrays Again, an array is a group of indexed values. For instance, instead of having individual class scores Score1, Score2, etc, you can have score[0], score[1]…score[30]. So, What’s the difference?

Arrays The difference is that the indexes can themselves be referred to by a variable! score[x] = 7 score[x + 1] = 4 score[y]= 9

Arrays When we want a group of related data, we may declare an Array object: myArray = new Array(50) This would set up 50 elements, from 0 to 49. There is no 50th element.

Arrays That indexing ability makes keeping track of related data very easy. Name[7] = “Fred” Lab1[7] = 5 Lab2[7] = 4 Midterm[7] = 12

Array Object: Sort Method Using the sort method, you can sort a numeric or alphabetic array. MyArray.sort()

Summary Strings and arrays are used in most scripts Learning them is necessary and a useful programming skill.