SlideShare a Scribd company logo
www.webstackacademy.com ‹#›
Strings and Array
JavaScript
www.webstackacademy.com ‹#›
 Strings
 Strings access methods
 Array
 Array access methods
 Multi dimensional arrays
Table of Content
www.webstackacademy.com ‹#›www.webstackacademy.com ‹#›
Strings
(Introduction to Strings)
www.webstackacademy.com ‹#›
What is String?
• String is a sequence of Unicode characters.
• Unicode characters are encoding standard that has widespread acceptance.
• Some of the most commonly used character encodings are
Encoding Description
UTF - 8 Widely used in email systems and on the internet.
UTF - 16 Used in windows, Java and by JavaScript, and often for plain text
and for word-processing data files on Windows.
UTF - 32 The mainly used in internal APIs where the data is single code
points or glyphs, rather than strings of characters.
www.webstackacademy.com ‹#›
Strings Syntax
<script>
var str = “ ”;
var str1 = “Hello World”;
var str2 = new String(“Hi”);
</script>
www.webstackacademy.com ‹#›
Strings - Immutable
Example:
<script>
var str = “Hello World”;
str[0] = “h”;
console.log(str); //will be “Hello World”
</script>
• In JavaScript strings are immutable or unchangeable.
• An immutable object is an object whose state cannot be modified after it is created.
www.webstackacademy.com ‹#›www.webstackacademy.com ‹#›
String Methods
(Pre-defined methods to perform various operations in strings)
www.webstackacademy.com ‹#›
Strings Methods
Method Description
length Returns the length of the string
concat() Joins the string with one or more strings
trim() Removes the white spaces from beginning and end of the string
replace() Replaces old string with the new string
substring() Returns the part of string
substr() Returns the part of string
www.webstackacademy.com ‹#›
Strings Methods
Method Description
indexOf() Returns the position of specified word
lastIndexOf() Returns the last occurrence of specified word
slice() Returns the part of the string
split() Converts string into array
includes() Returns true if string includes the specified word.
www.webstackacademy.com ‹#›
The length() Method
 The length method returns the size of the string.
Example :
var str = “Hello World”;
var len = str.length;
document.write(“Length of the string ” + len);
Syntax :
var length = string.length;
www.webstackacademy.com ‹#›
The concat() Method
 The concat() method will join the string with one or more strings.
Syntax :
var str1 = str.concat(“hello”,” “,”World”);
or
var str2 = str.concat(str1,str2,str3…..strN);
www.webstackacademy.com ‹#›
The concat() Method
Example :
var str1 = “Hello World”;
var str2 = “Welcome”;
var concatString = str1.concat(“ ”, str2, ” “, “to WSA”);
document.write(“Concatenation of string” + concatString);
www.webstackacademy.com ‹#›
The trim() Method
 The trim() method will remove the spaces from beginning and end of the
strings.
Syntax :
var result = string.trim();
Example :
var str1 = “ Hello World ”;
var trimmedString = str1.trim();
console.log (“After trim” +trimmedString);
www.webstackacademy.com ‹#›
The trimStart() or trimLeft() Method
 The trimStart() or trimLeft() methods will remove the spaces from the
beginning of the strings.
Syntax :
var result = string.trimLeft();
Or
var result = string.trimStart();
www.webstackacademy.com ‹#›
The trimStart() or trimLeft() Method
Example :
var str1 = “ Hello World ”;
var trimmedStart = str1.trimStart();
var trimmedLeft = str1.trimLeft();
console.log(“After trim” +trimmedStart);
console.log(“<br>After trim” +trimmedLeft);
www.webstackacademy.com ‹#›
The trimEnd() or trimRight() Method
 The trimEnd() or trimRight() methods will remove the spaces from the
beginning of the strings.
Syntax :
var result = string.trimEnd();
Or
var result = string.trimRight();
www.webstackacademy.com ‹#›
The trimEnd() or trimRight() Method
Example :
var str1 = “ Hello World ”;
var trimmedEnd = str1.trimEnd();
var trimmedRight = str1.trimRight();
console.log(“After trim” +trimmedEnd);
console.log(“<br>After trim” +trimmedRight);
www.webstackacademy.com ‹#›
The replace() Method
 The replace() method will replace the specified string into new string.
Syntax :
var replacedStr = str.replace(‘string to replace’,’new string’);
Or
var replacedStr = str.replace(RegularExpression, ’new string’);
www.webstackacademy.com ‹#›
The replace() Method
Example 1:
var str1 =“Welcome to JS World”;
var repStr = str1.replace(‘JS’,’JavaScript’);
console.log(“Replaced String” +repStr);
Example 2:
var str =“A blue bottle with a blur liquid is on a blue table Blue”;
var replacedStr = str.replace(/blue/g, ”green”);
document.write(“After replace” +replacedStr);
www.webstackacademy.com ‹#›
The substring() Method
 The substring() method will return the part of the strings.
Syntax :
var subStr = str.substring(startIndex, EndIndex);
Example :
var str1 =“Javascript World”;
var subStr = str1.substring(0,10);
document.write(“Subtring is: ” +subStr);
www.webstackacademy.com ‹#›
The substr() Method
 The substr() method will return the part of the strings.
Syntax :
var subStr = str.substr(startIndex, numberOfCharacters);
Example :
var str1 =“Javascript World”;
var subStr = str1.substr(0,10);
document.write(“Subtring is: ” +subStr);
www.webstackacademy.com ‹#›
The indexOf() Method
The indexOf() method will return the position of first occurrence of the specified string
Syntax :
var index = str.indexOf(“string”);
Example :
var str1 =“Javascript World”;
var indexStr = str1.indexOf(“World”);
document.write(“Index of world” +indexStr);
www.webstackacademy.com ‹#›
The lastIndexOf() Method
The lastIndexOf() method will return the position of last occurrence of the specified string
Syntax :
var lastIndex = str.lastIndexOf(“string”);
Example :
var str1 =“Javascript World! Welcome to World”;
var lastIndex = str1.lastIndexOf(“World”);
document.write(“Last Index of world” +lastIndex);
www.webstackacademy.com ‹#›
Exercise
Write a JavaScript program to extract the user name and domain name.
• Accept email address from the user, extract the user name and the domain name, for
• example,
Input: abc.xyz@gmail.com
Output: username: abc.xyz
domain : gmail.com
www.webstackacademy.com ‹#›
The slice() Method
 The slice() method will return the part of the strings.
Syntax :
var slicedStr = str.slice(startIndex, EndIndex);
Example :
var str =“Javascript world”;
var slicedStr = str.slice(1,5);
document.write(“Sliced String” +slicedStr);
www.webstackacademy.com ‹#›
The split() Method
 The split() method will convert string into array of strings.
Syntax :
var splitStr = str.split(separator,limit);
Example :
var str =“Javascript world. Welcome to WSA”;
var splitStr = str.split(“ “)
document.write(“Array of string” +splitStr);
var splitLimit = str.split(“ “,2);
document.write(“Array of string” +splitLimit);
www.webstackacademy.com ‹#›
The includes() Method
The includes() method will true if string includes the specified word else returns the false.
Syntax :
var includesStr = str.includes(searchString, position);
Example :
var str = 'To be, or not to be, that is the question.';
console.log(str.includes('To be'));
console.log(str.includes('question',0));
console.log(str.includes('nonexistent'));
www.webstackacademy.com ‹#›
Exercise
www.webstackacademy.com ‹#›
Convert the given string into title case with following rules:
• Capitalize the first letter of each word. Capitalize nouns, pronouns, adjectives, verbs,
adverbs, and subordinate conjunctions.
• Lowercase articles (a, an, the), coordinating conjunctions, and prepositions (under,
between, over, on, at).
• Lowercase the 'to' in an infinitive (I want to play guitar).
Examples:
• How Are You Doing Today?
• Our Office between Metro and Barton Centre
• What Is the Need of This Expensive Phone?
www.webstackacademy.com ‹#›
Exercise
www.webstackacademy.com ‹#›
1. Count number of palindromes in a given string:
2. Special Palindrome
• In English we call a particular string as palindrome if it reads the same way from left and
right (ex: Malayalam, mom etc..)
• However there are some special kind of palindromes are there which will have:
1. Upper case characters
2. Special characters
3. Spaces in-between.
Examples:
1. "Madam, I’m Adam“
2. "A nut for a jar of tuna.“
3. "Are we not pure? “No, sir!” Panama’s moody Noriega brags. It is garbage!”
Irony dooms a man—a prisoner up to new era."
www.webstackacademy.com ‹#›www.webstackacademy.com ‹#›
Arrays
(Introduction to Arrays)
www.webstackacademy.com ‹#›
What is an Array?
 Array is a collection of similar or different data types
 Each data in array is called an element
 Each elements has a numeric position, known as its index / indices, in the array
 The index numbers start from zero
 In JavaScript, Array is also an object. The typeof operator will return the same
 Array object has length property which returns the total number of elements
www.webstackacademy.com ‹#›
Array
(Syntax – Using [ ] )
Syntax :
// Creates initialized array
var array-name = [item1, item2, …];
// Creates empty
var array-name = [ ];
www.webstackacademy.com ‹#›
Array
(Syntax – Using constructor)
Syntax :
var array-name = new Array(item1, item2, item3);
Or
var array-name = Array(item1, item2, item3);
Or
var array-name = Array(array-length);
www.webstackacademy.com ‹#›
Array - Example
Example :
var array = [10, 20, 30, 40, 50];
Or
var array = new Array(10, 20, 30, 40, 50);
Or
var array = Array(3);
www.webstackacademy.com ‹#›
Array Access – Using loop
for ( let idx = 0; idx < 5; idx++ ) {
document.write(“Element at index ” + idx + “ is ” + myArray[idx]);
}
for ( let idx in myArray ) {
document.write(“Element at index ” + idx + “ is ” + myArray[idx]);
}
www.webstackacademy.com ‹#›
Array - Heterogeneous
Each element in an array can be of different types
var mixArray = [“Student”, 95, true];
for(let idx = 0; idx < 3; idx++) {
console.log (mixArray[idx]);
}
www.webstackacademy.com ‹#›
Exercise
 WAP to create an array with 10 integers and find out the following:
 Sum of all number
 Average
 Maximum value & Minimum value
 WAP to reverse an array elements.
www.webstackacademy.com ‹#›www.webstackacademy.com ‹#›
Array Methods
(Pre-defined methods to perform various operations in array)
www.webstackacademy.com ‹#›
Array Methods
Method Description
join() Concatenates all the elements of array into string
pop() Deletes last element of an array
push() Appends new element in the last of array
sort() Sorts an array in alphabetical order
reverse() Reverses array elements order in the array
www.webstackacademy.com ‹#›
Array Methods
Method Description
shift() Removes first element from the array and shifts all other element
to a lower index
unshift() Unshift method adds elements to the beginning of an array and
return new length of array
slice() The array slice method returns part of an array
splice() The array splice method can be used for adding and/or removing
elements from an array
www.webstackacademy.com ‹#›
Array Methods
Method Description
Filter() Creates a new array with all elements that pass the test
implemented by the provided function.
map() Creates a new array with the results of calling a provided function
on each element in the calling array.
www.webstackacademy.com ‹#›
The join() Method
 The join() method converts all the elements of an array to strings and
concatenates them, returning the resulting string
 It behaves like toString(), but we can specify separator
Example :
var fruits = ["Banana", "Orange","Apple", "Mango"];
var str = fruits.join(" + ");
document.write(str);
www.webstackacademy.com ‹#›
The push() and pop() methods
Stack operations – LIFO
var numStack = [10, 20, 30, 40, 50];
numStack.pop(); // Pop an element
for (let idx=0; idx <numStack.length; idx++) {
document.write(numStack[idx] + "<br>");
}
numStack.push(100); // Push an element
for (let idx=0; idx <numStack.length; idx++) {
document.write(numStack[idx] + "<br>");
}
www.webstackacademy.com ‹#›
The shift() methods
Example:
var array1 = [1, 2, 3];
var firstElement = array1.shift();
console.log(array1);// expected output: Array [2, 3]
console.log(firstElement);// expected output: 1
The shift() method removes the first element from an array and returns
that removed element.
Syntax
array.shift();
www.webstackacademy.com ‹#›
The unshift() methods
Example:
var array1 = [1, 2, 3];
array1.unshift(2);
console.log(array1);
array1.unshift(5,8);
console.log(array1);
The unshift() method adds one or more elements to the beginning of an
array and returns the new length of the array.
Syntax
array.unshift();
www.webstackacademy.com ‹#›
The sort() Method
The sort() method sorts an array in alphabetic order
var numList = [‘banana’, ‘apple’, ‘mango’, ‘grapes’];
numList.sort();
for (let idx = 0; idx < numList.length; idx++){
document.write(numList[idx] + "<br>");
}
www.webstackacademy.com ‹#›
The reverse() Method
The reverse() method reverses the elements in an array
var numList = [55, 3, 16, 21];
numList.reverse();
for(let idx = 0; idx < numList.length; idx++){
document.write(numList[idx] + "<br>");
}
www.webstackacademy.com ‹#›
Exercise
 WAP to represent two sets of integers. Find out union and intersection of those two
sets (Ref – Set theory)
 Assume there are duplicates in the array
 Hint – Write a findElement() function to check if an element is present in an array or not
• WAP to find Nth largest element in a given array
• WAP to perform shift operations of a given element
 Shift Nth element by right by M positions
 Shift Nth element by left by M positions
www.webstackacademy.com ‹#›
Thesplice() Method
Syntax:
array.splice(startIndex, number of elements, elements to
add);
www.webstackacademy.com ‹#›
The splice() method will change the content of original array by removing or
adding the element.
www.webstackacademy.com ‹#›
Thesplice() Method
var ar = [1, 4, 9, 10, 11, 16];
ar.splice(1,3);// will remove the elements
console.log(ar);
ar.splice(1,0,5);// will insert the element 5 at index 1
console.log(ar);
www.webstackacademy.com ‹#›
www.webstackacademy.com ‹#›
TheforEach()Method
www.webstackacademy.com ‹#›
The map() method creates a new array with the results of calling a provided
function on each element in the calling array.
Syntax:
arrayName.forEach(callback_function(currentItem, index, array) {
//Application Logic
});
www.webstackacademy.com ‹#›
TheforEach() Method
Example:
var age = [21,19,34,56,23,20,17,65,76,15,35,14,13,25];
age.forEach(function(item) {
document.write(item+" ");
});
www.webstackacademy.com ‹#›
www.webstackacademy.com ‹#›
Thefilter() Method
www.webstackacademy.com ‹#›
Filter() method creates a new array with all elements that pass the test implemented
by the provided function.
Syntax:
var new_array =
current_array.filter(function(currentItem,index,array)
{
//Application Logic to filter current array items
//return items for new array
});
www.webstackacademy.com ‹#›
Thefilter() Method
Example:
var words = ['limit', 'elite', 'exuberant', 'destruction‘];
function word(elem) {
return elem.length > 6;
}
var result = words.filter(word);
console.log(result);
// expected output: Array ["exuberant", "destruction“];
www.webstackacademy.com ‹#›
www.webstackacademy.com ‹#›
Exercise
www.webstackacademy.com ‹#›
Write a JavaScript program to squeeze a word in given sentence.
For example:
1. Input : what is what so what
Output: what is so
2. Input : I mean they can't be so mean
Output : I mean they can't be so
3. Input : Butler bought bitter butter but he made it as a better butter by adding
sweeter butter
Output : Butler bought bitter butter but he made it as a better by adding sweeter
www.webstackacademy.com ‹#›
Themap() Method
www.webstackacademy.com ‹#›
The map() method creates a new array with the results of calling a provided
function on each element in the calling array.
Syntax:
var new_array = current_array.map(function(currentItem, index, array) {
//Application Logic
//Return elements for new array
});
www.webstackacademy.com ‹#›
Themap() Method
Example:
var curArray = [1, 4, 9, 16];// pass a function to map
var doubleArray = curArray.map(doubleItem);
function doubleItem(currentItem) {
return 2 * currentItem;
}
console.log(doubleArray);
www.webstackacademy.com ‹#›
www.webstackacademy.com ‹#›
Exercise
www.webstackacademy.com ‹#›
Write a JavaScript program to greet the guest.
For example:
1. Input : [‘Ram’,’Radhika’,’John’,’Sumit’]
Output: Welcome Ram
Welcome Radhika
Welcome John
Welcome Sumit
www.webstackacademy.com ‹#›www.webstackacademy.com ‹#›
Multidimensional Array
The matrix
www.webstackacademy.com ‹#›
Multidimensional Array
Declaring Multidimensional Array
var array2d = [ [10, 20, 30], [40, 50, 60], [70, 80, 90] ];
for(let idx = 0; idx < array2d.length; idx++) {
for(let jdx = 0; jdx < array2d[idx].length; jdx++) {
document.write(array2d[idx][jdx] + " ");
}
document.write("<br>");
}
www.webstackacademy.com ‹#›
Exercise
 WAP to find out sum of diagonal elements in a 2D array
 WAP to find max and min value in a given row
 WAP to multiply two matrix using 2D arrays
www.webstackacademy.com ‹#›
WebStack Academy
#83, Farah Towers,
1st Floor, MG Road,
Bangalore – 560001
M: +91-809 555 7332
E: training@webstackacademy.com
WSA in Social Media:

More Related Content

What's hot (20)

javascript objects
javascript objectsjavascript objects
javascript objects
Vijay Kalyan
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
Partnered Health
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla
 
Css Ppt
Css PptCss Ppt
Css Ppt
Hema Prasanth
 
Java script
Java scriptJava script
Java script
Shyam Khant
 
jQuery
jQueryjQuery
jQuery
Dileep Mishra
 
Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
Priya Goyal
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Php array
Php arrayPhp array
Php array
Nikul Shah
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
Jussi Pohjolainen
 
Java script
Java scriptJava script
Java script
Sadeek Mohammed
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv21
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
Maitree Patel
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
Jeff Fox
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
Hassan Dar
 
Xml schema
Xml schemaXml schema
Xml schema
Prabhakaran V M
 
JavaScript Control Statements I
JavaScript Control Statements IJavaScript Control Statements I
JavaScript Control Statements I
Reem Alattas
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
Yao Nien Chung
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
javascript objects
javascript objectsjavascript objects
javascript objects
Vijay Kalyan
 
Dom(document object model)
Dom(document object model)Dom(document object model)
Dom(document object model)
Partnered Health
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
JavaScript: Variables and Functions
JavaScript: Variables and FunctionsJavaScript: Variables and Functions
JavaScript: Variables and Functions
Jussi Pohjolainen
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
ShahDhruv21
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
Maitree Patel
 
JSON: The Basics
JSON: The BasicsJSON: The Basics
JSON: The Basics
Jeff Fox
 
Javascript arrays
Javascript arraysJavascript arrays
Javascript arrays
Hassan Dar
 
JavaScript Control Statements I
JavaScript Control Statements IJavaScript Control Statements I
JavaScript Control Statements I
Reem Alattas
 
Lets make a better react form
Lets make a better react formLets make a better react form
Lets make a better react form
Yao Nien Chung
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 

Similar to JavaScript - Chapter 10 - Strings and Arrays (20)

Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptxWeb Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
samaghorab
 
Web Development_Sec6_Java secriptvvvvv.pdf
Web Development_Sec6_Java secriptvvvvv.pdfWeb Development_Sec6_Java secriptvvvvv.pdf
Web Development_Sec6_Java secriptvvvvv.pdf
samaghorab
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
dineshrana201992
 
Ch08 - Manipulating Data in Strings and Arrays
Ch08 - Manipulating Data in Strings and ArraysCh08 - Manipulating Data in Strings and Arrays
Ch08 - Manipulating Data in Strings and Arrays
dcomfort6819
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
Reem Alattas
 
Javascript string method
Javascript string methodJavascript string method
Javascript string method
chauhankapil
 
CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38
Bilal Ahmed
 
Java script objects 2
Java script objects 2Java script objects 2
Java script objects 2
H K
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
Julie Iskander
 
1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications
surajshreyans
 
advancing in js Scripting languages pt4.pptx
advancing in js Scripting languages pt4.pptxadvancing in js Scripting languages pt4.pptx
advancing in js Scripting languages pt4.pptx
KisakyeDennis
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
Terry Yoast
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
tonyh1
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
KennyPratheepKumar
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29
Bilal Ahmed
 
Java script
 Java script Java script
Java script
bosybosy
 
An Introduction to JavaScript
An Introduction to JavaScriptAn Introduction to JavaScript
An Introduction to JavaScript
tonyh1
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 
Java script
Java scriptJava script
Java script
Shagufta shaheen
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
sandeshshahapur
 
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptxWeb Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
Web Development_Sec6_kkkkkkkkkkkkkkkkkkkkkkkkkJS.pptx
samaghorab
 
Web Development_Sec6_Java secriptvvvvv.pdf
Web Development_Sec6_Java secriptvvvvv.pdfWeb Development_Sec6_Java secriptvvvvv.pdf
Web Development_Sec6_Java secriptvvvvv.pdf
samaghorab
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
dineshrana201992
 
Ch08 - Manipulating Data in Strings and Arrays
Ch08 - Manipulating Data in Strings and ArraysCh08 - Manipulating Data in Strings and Arrays
Ch08 - Manipulating Data in Strings and Arrays
dcomfort6819
 
JavaScript Objects
JavaScript ObjectsJavaScript Objects
JavaScript Objects
Reem Alattas
 
Javascript string method
Javascript string methodJavascript string method
Javascript string method
chauhankapil
 
CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38CS101- Introduction to Computing- Lecture 38
CS101- Introduction to Computing- Lecture 38
Bilal Ahmed
 
Java script objects 2
Java script objects 2Java script objects 2
Java script objects 2
H K
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
Julie Iskander
 
1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications1-JAVA SCRIPT. servere-side applications vs client side applications
1-JAVA SCRIPT. servere-side applications vs client side applications
surajshreyans
 
advancing in js Scripting languages pt4.pptx
advancing in js Scripting languages pt4.pptxadvancing in js Scripting languages pt4.pptx
advancing in js Scripting languages pt4.pptx
KisakyeDennis
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
Terry Yoast
 
An introduction to javascript
An introduction to javascriptAn introduction to javascript
An introduction to javascript
tonyh1
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29
Bilal Ahmed
 
Java script
 Java script Java script
Java script
bosybosy
 
An Introduction to JavaScript
An Introduction to JavaScriptAn Introduction to JavaScript
An Introduction to JavaScript
tonyh1
 
GeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheetGeoGebra JavaScript CheatSheet
GeoGebra JavaScript CheatSheet
Jose Perez
 
gdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptxgdscWorkShopJavascriptintroductions.pptx
gdscWorkShopJavascriptintroductions.pptx
sandeshshahapur
 
Ad

More from WebStackAcademy (20)

Webstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement JourneyWebstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement Journey
WebStackAcademy
 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per SecondWSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per Second
WebStackAcademy
 
WSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer CourseWSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer Course
WebStackAcademy
 
Career Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy
 
Webstack Academy - Internship Kick Off
Webstack Academy - Internship Kick OffWebstack Academy - Internship Kick Off
Webstack Academy - Internship Kick Off
WebStackAcademy
 
Building Your Online Portfolio
Building Your Online PortfolioBuilding Your Online Portfolio
Building Your Online Portfolio
WebStackAcademy
 
Front-End Developer's Career Roadmap
Front-End Developer's Career RoadmapFront-End Developer's Career Roadmap
Front-End Developer's Career Roadmap
WebStackAcademy
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationAngular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase Integration
WebStackAcademy
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
WebStackAcademy
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
WebStackAcademy
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
WebStackAcademy
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy
 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
WebStackAcademy
 
Webstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement JourneyWebstack Academy - Course Demo Webinar and Placement Journey
Webstack Academy - Course Demo Webinar and Placement Journey
WebStackAcademy
 
WSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per SecondWSA: Scaling Web Service to Handle Millions of Requests per Second
WSA: Scaling Web Service to Handle Millions of Requests per Second
WebStackAcademy
 
WSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer CourseWSA: Course Demo Webinar - Full Stack Developer Course
WSA: Course Demo Webinar - Full Stack Developer Course
WebStackAcademy
 
Career Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and OpportunitiesCareer Building in AI - Technologies, Trends and Opportunities
Career Building in AI - Technologies, Trends and Opportunities
WebStackAcademy
 
Webstack Academy - Internship Kick Off
Webstack Academy - Internship Kick OffWebstack Academy - Internship Kick Off
Webstack Academy - Internship Kick Off
WebStackAcademy
 
Building Your Online Portfolio
Building Your Online PortfolioBuilding Your Online Portfolio
Building Your Online Portfolio
WebStackAcademy
 
Front-End Developer's Career Roadmap
Front-End Developer's Career RoadmapFront-End Developer's Career Roadmap
Front-End Developer's Career Roadmap
WebStackAcademy
 
Angular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and AuthorizationAngular - Chapter 9 - Authentication and Authorization
Angular - Chapter 9 - Authentication and Authorization
WebStackAcademy
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
WebStackAcademy
 
Angular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase IntegrationAngular - Chapter 6 - Firebase Integration
Angular - Chapter 6 - Firebase Integration
WebStackAcademy
 
Angular - Chapter 5 - Directives
 Angular - Chapter 5 - Directives Angular - Chapter 5 - Directives
Angular - Chapter 5 - Directives
WebStackAcademy
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
WebStackAcademy
 
Angular - Chapter 3 - Components
Angular - Chapter 3 - ComponentsAngular - Chapter 3 - Components
Angular - Chapter 3 - Components
WebStackAcademy
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
WebStackAcademy
 
Angular - Chapter 1 - Introduction
 Angular - Chapter 1 - Introduction Angular - Chapter 1 - Introduction
Angular - Chapter 1 - Introduction
WebStackAcademy
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)JavaScript - Chapter 13 - Browser Object Model(BOM)
JavaScript - Chapter 13 - Browser Object Model(BOM)
WebStackAcademy
 
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
 JavaScript - Chapter 9 - TypeConversion and Regular Expressions  JavaScript - Chapter 9 - TypeConversion and Regular Expressions
JavaScript - Chapter 9 - TypeConversion and Regular Expressions
WebStackAcademy
 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced Functions
WebStackAcademy
 
JavaScript - Chapter 5 - Operators
 JavaScript - Chapter 5 - Operators JavaScript - Chapter 5 - Operators
JavaScript - Chapter 5 - Operators
WebStackAcademy
 
Ad

Recently uploaded (20)

Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | BluebashMCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
Bluebash
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
FME Beyond Data Processing Creating A Dartboard Accuracy App
FME Beyond Data Processing Creating A Dartboard Accuracy AppFME Beyond Data Processing Creating A Dartboard Accuracy App
FME Beyond Data Processing Creating A Dartboard Accuracy App
Safe Software
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0
RodrigoMori7
 
Soulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate reviewSoulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate review
Soulmaite
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | BluebashMCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
Bluebash
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
FME Beyond Data Processing Creating A Dartboard Accuracy App
FME Beyond Data Processing Creating A Dartboard Accuracy AppFME Beyond Data Processing Creating A Dartboard Accuracy App
FME Beyond Data Processing Creating A Dartboard Accuracy App
Safe Software
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0
RodrigoMori7
 
Soulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate reviewSoulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate review
Soulmaite
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 

JavaScript - Chapter 10 - Strings and Arrays

  • 2. www.webstackacademy.com ‹#›  Strings  Strings access methods  Array  Array access methods  Multi dimensional arrays Table of Content
  • 4. www.webstackacademy.com ‹#› What is String? • String is a sequence of Unicode characters. • Unicode characters are encoding standard that has widespread acceptance. • Some of the most commonly used character encodings are Encoding Description UTF - 8 Widely used in email systems and on the internet. UTF - 16 Used in windows, Java and by JavaScript, and often for plain text and for word-processing data files on Windows. UTF - 32 The mainly used in internal APIs where the data is single code points or glyphs, rather than strings of characters.
  • 5. www.webstackacademy.com ‹#› Strings Syntax <script> var str = “ ”; var str1 = “Hello World”; var str2 = new String(“Hi”); </script>
  • 6. www.webstackacademy.com ‹#› Strings - Immutable Example: <script> var str = “Hello World”; str[0] = “h”; console.log(str); //will be “Hello World” </script> • In JavaScript strings are immutable or unchangeable. • An immutable object is an object whose state cannot be modified after it is created.
  • 7. www.webstackacademy.com ‹#›www.webstackacademy.com ‹#› String Methods (Pre-defined methods to perform various operations in strings)
  • 8. www.webstackacademy.com ‹#› Strings Methods Method Description length Returns the length of the string concat() Joins the string with one or more strings trim() Removes the white spaces from beginning and end of the string replace() Replaces old string with the new string substring() Returns the part of string substr() Returns the part of string
  • 9. www.webstackacademy.com ‹#› Strings Methods Method Description indexOf() Returns the position of specified word lastIndexOf() Returns the last occurrence of specified word slice() Returns the part of the string split() Converts string into array includes() Returns true if string includes the specified word.
  • 10. www.webstackacademy.com ‹#› The length() Method  The length method returns the size of the string. Example : var str = “Hello World”; var len = str.length; document.write(“Length of the string ” + len); Syntax : var length = string.length;
  • 11. www.webstackacademy.com ‹#› The concat() Method  The concat() method will join the string with one or more strings. Syntax : var str1 = str.concat(“hello”,” “,”World”); or var str2 = str.concat(str1,str2,str3…..strN);
  • 12. www.webstackacademy.com ‹#› The concat() Method Example : var str1 = “Hello World”; var str2 = “Welcome”; var concatString = str1.concat(“ ”, str2, ” “, “to WSA”); document.write(“Concatenation of string” + concatString);
  • 13. www.webstackacademy.com ‹#› The trim() Method  The trim() method will remove the spaces from beginning and end of the strings. Syntax : var result = string.trim(); Example : var str1 = “ Hello World ”; var trimmedString = str1.trim(); console.log (“After trim” +trimmedString);
  • 14. www.webstackacademy.com ‹#› The trimStart() or trimLeft() Method  The trimStart() or trimLeft() methods will remove the spaces from the beginning of the strings. Syntax : var result = string.trimLeft(); Or var result = string.trimStart();
  • 15. www.webstackacademy.com ‹#› The trimStart() or trimLeft() Method Example : var str1 = “ Hello World ”; var trimmedStart = str1.trimStart(); var trimmedLeft = str1.trimLeft(); console.log(“After trim” +trimmedStart); console.log(“<br>After trim” +trimmedLeft);
  • 16. www.webstackacademy.com ‹#› The trimEnd() or trimRight() Method  The trimEnd() or trimRight() methods will remove the spaces from the beginning of the strings. Syntax : var result = string.trimEnd(); Or var result = string.trimRight();
  • 17. www.webstackacademy.com ‹#› The trimEnd() or trimRight() Method Example : var str1 = “ Hello World ”; var trimmedEnd = str1.trimEnd(); var trimmedRight = str1.trimRight(); console.log(“After trim” +trimmedEnd); console.log(“<br>After trim” +trimmedRight);
  • 18. www.webstackacademy.com ‹#› The replace() Method  The replace() method will replace the specified string into new string. Syntax : var replacedStr = str.replace(‘string to replace’,’new string’); Or var replacedStr = str.replace(RegularExpression, ’new string’);
  • 19. www.webstackacademy.com ‹#› The replace() Method Example 1: var str1 =“Welcome to JS World”; var repStr = str1.replace(‘JS’,’JavaScript’); console.log(“Replaced String” +repStr); Example 2: var str =“A blue bottle with a blur liquid is on a blue table Blue”; var replacedStr = str.replace(/blue/g, ”green”); document.write(“After replace” +replacedStr);
  • 20. www.webstackacademy.com ‹#› The substring() Method  The substring() method will return the part of the strings. Syntax : var subStr = str.substring(startIndex, EndIndex); Example : var str1 =“Javascript World”; var subStr = str1.substring(0,10); document.write(“Subtring is: ” +subStr);
  • 21. www.webstackacademy.com ‹#› The substr() Method  The substr() method will return the part of the strings. Syntax : var subStr = str.substr(startIndex, numberOfCharacters); Example : var str1 =“Javascript World”; var subStr = str1.substr(0,10); document.write(“Subtring is: ” +subStr);
  • 22. www.webstackacademy.com ‹#› The indexOf() Method The indexOf() method will return the position of first occurrence of the specified string Syntax : var index = str.indexOf(“string”); Example : var str1 =“Javascript World”; var indexStr = str1.indexOf(“World”); document.write(“Index of world” +indexStr);
  • 23. www.webstackacademy.com ‹#› The lastIndexOf() Method The lastIndexOf() method will return the position of last occurrence of the specified string Syntax : var lastIndex = str.lastIndexOf(“string”); Example : var str1 =“Javascript World! Welcome to World”; var lastIndex = str1.lastIndexOf(“World”); document.write(“Last Index of world” +lastIndex);
  • 24. www.webstackacademy.com ‹#› Exercise Write a JavaScript program to extract the user name and domain name. • Accept email address from the user, extract the user name and the domain name, for • example, Input: [email protected] Output: username: abc.xyz domain : gmail.com
  • 25. www.webstackacademy.com ‹#› The slice() Method  The slice() method will return the part of the strings. Syntax : var slicedStr = str.slice(startIndex, EndIndex); Example : var str =“Javascript world”; var slicedStr = str.slice(1,5); document.write(“Sliced String” +slicedStr);
  • 26. www.webstackacademy.com ‹#› The split() Method  The split() method will convert string into array of strings. Syntax : var splitStr = str.split(separator,limit); Example : var str =“Javascript world. Welcome to WSA”; var splitStr = str.split(“ “) document.write(“Array of string” +splitStr); var splitLimit = str.split(“ “,2); document.write(“Array of string” +splitLimit);
  • 27. www.webstackacademy.com ‹#› The includes() Method The includes() method will true if string includes the specified word else returns the false. Syntax : var includesStr = str.includes(searchString, position); Example : var str = 'To be, or not to be, that is the question.'; console.log(str.includes('To be')); console.log(str.includes('question',0)); console.log(str.includes('nonexistent'));
  • 28. www.webstackacademy.com ‹#› Exercise www.webstackacademy.com ‹#› Convert the given string into title case with following rules: • Capitalize the first letter of each word. Capitalize nouns, pronouns, adjectives, verbs, adverbs, and subordinate conjunctions. • Lowercase articles (a, an, the), coordinating conjunctions, and prepositions (under, between, over, on, at). • Lowercase the 'to' in an infinitive (I want to play guitar). Examples: • How Are You Doing Today? • Our Office between Metro and Barton Centre • What Is the Need of This Expensive Phone?
  • 29. www.webstackacademy.com ‹#› Exercise www.webstackacademy.com ‹#› 1. Count number of palindromes in a given string: 2. Special Palindrome • In English we call a particular string as palindrome if it reads the same way from left and right (ex: Malayalam, mom etc..) • However there are some special kind of palindromes are there which will have: 1. Upper case characters 2. Special characters 3. Spaces in-between. Examples: 1. "Madam, I’m Adam“ 2. "A nut for a jar of tuna.“ 3. "Are we not pure? “No, sir!” Panama’s moody Noriega brags. It is garbage!” Irony dooms a man—a prisoner up to new era."
  • 31. www.webstackacademy.com ‹#› What is an Array?  Array is a collection of similar or different data types  Each data in array is called an element  Each elements has a numeric position, known as its index / indices, in the array  The index numbers start from zero  In JavaScript, Array is also an object. The typeof operator will return the same  Array object has length property which returns the total number of elements
  • 32. www.webstackacademy.com ‹#› Array (Syntax – Using [ ] ) Syntax : // Creates initialized array var array-name = [item1, item2, …]; // Creates empty var array-name = [ ];
  • 33. www.webstackacademy.com ‹#› Array (Syntax – Using constructor) Syntax : var array-name = new Array(item1, item2, item3); Or var array-name = Array(item1, item2, item3); Or var array-name = Array(array-length);
  • 34. www.webstackacademy.com ‹#› Array - Example Example : var array = [10, 20, 30, 40, 50]; Or var array = new Array(10, 20, 30, 40, 50); Or var array = Array(3);
  • 35. www.webstackacademy.com ‹#› Array Access – Using loop for ( let idx = 0; idx < 5; idx++ ) { document.write(“Element at index ” + idx + “ is ” + myArray[idx]); } for ( let idx in myArray ) { document.write(“Element at index ” + idx + “ is ” + myArray[idx]); }
  • 36. www.webstackacademy.com ‹#› Array - Heterogeneous Each element in an array can be of different types var mixArray = [“Student”, 95, true]; for(let idx = 0; idx < 3; idx++) { console.log (mixArray[idx]); }
  • 37. www.webstackacademy.com ‹#› Exercise  WAP to create an array with 10 integers and find out the following:  Sum of all number  Average  Maximum value & Minimum value  WAP to reverse an array elements.
  • 38. www.webstackacademy.com ‹#›www.webstackacademy.com ‹#› Array Methods (Pre-defined methods to perform various operations in array)
  • 39. www.webstackacademy.com ‹#› Array Methods Method Description join() Concatenates all the elements of array into string pop() Deletes last element of an array push() Appends new element in the last of array sort() Sorts an array in alphabetical order reverse() Reverses array elements order in the array
  • 40. www.webstackacademy.com ‹#› Array Methods Method Description shift() Removes first element from the array and shifts all other element to a lower index unshift() Unshift method adds elements to the beginning of an array and return new length of array slice() The array slice method returns part of an array splice() The array splice method can be used for adding and/or removing elements from an array
  • 41. www.webstackacademy.com ‹#› Array Methods Method Description Filter() Creates a new array with all elements that pass the test implemented by the provided function. map() Creates a new array with the results of calling a provided function on each element in the calling array.
  • 42. www.webstackacademy.com ‹#› The join() Method  The join() method converts all the elements of an array to strings and concatenates them, returning the resulting string  It behaves like toString(), but we can specify separator Example : var fruits = ["Banana", "Orange","Apple", "Mango"]; var str = fruits.join(" + "); document.write(str);
  • 43. www.webstackacademy.com ‹#› The push() and pop() methods Stack operations – LIFO var numStack = [10, 20, 30, 40, 50]; numStack.pop(); // Pop an element for (let idx=0; idx <numStack.length; idx++) { document.write(numStack[idx] + "<br>"); } numStack.push(100); // Push an element for (let idx=0; idx <numStack.length; idx++) { document.write(numStack[idx] + "<br>"); }
  • 44. www.webstackacademy.com ‹#› The shift() methods Example: var array1 = [1, 2, 3]; var firstElement = array1.shift(); console.log(array1);// expected output: Array [2, 3] console.log(firstElement);// expected output: 1 The shift() method removes the first element from an array and returns that removed element. Syntax array.shift();
  • 45. www.webstackacademy.com ‹#› The unshift() methods Example: var array1 = [1, 2, 3]; array1.unshift(2); console.log(array1); array1.unshift(5,8); console.log(array1); The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array. Syntax array.unshift();
  • 46. www.webstackacademy.com ‹#› The sort() Method The sort() method sorts an array in alphabetic order var numList = [‘banana’, ‘apple’, ‘mango’, ‘grapes’]; numList.sort(); for (let idx = 0; idx < numList.length; idx++){ document.write(numList[idx] + "<br>"); }
  • 47. www.webstackacademy.com ‹#› The reverse() Method The reverse() method reverses the elements in an array var numList = [55, 3, 16, 21]; numList.reverse(); for(let idx = 0; idx < numList.length; idx++){ document.write(numList[idx] + "<br>"); }
  • 48. www.webstackacademy.com ‹#› Exercise  WAP to represent two sets of integers. Find out union and intersection of those two sets (Ref – Set theory)  Assume there are duplicates in the array  Hint – Write a findElement() function to check if an element is present in an array or not • WAP to find Nth largest element in a given array • WAP to perform shift operations of a given element  Shift Nth element by right by M positions  Shift Nth element by left by M positions
  • 49. www.webstackacademy.com ‹#› Thesplice() Method Syntax: array.splice(startIndex, number of elements, elements to add); www.webstackacademy.com ‹#› The splice() method will change the content of original array by removing or adding the element.
  • 50. www.webstackacademy.com ‹#› Thesplice() Method var ar = [1, 4, 9, 10, 11, 16]; ar.splice(1,3);// will remove the elements console.log(ar); ar.splice(1,0,5);// will insert the element 5 at index 1 console.log(ar); www.webstackacademy.com ‹#›
  • 51. www.webstackacademy.com ‹#› TheforEach()Method www.webstackacademy.com ‹#› The map() method creates a new array with the results of calling a provided function on each element in the calling array. Syntax: arrayName.forEach(callback_function(currentItem, index, array) { //Application Logic });
  • 52. www.webstackacademy.com ‹#› TheforEach() Method Example: var age = [21,19,34,56,23,20,17,65,76,15,35,14,13,25]; age.forEach(function(item) { document.write(item+" "); }); www.webstackacademy.com ‹#›
  • 53. www.webstackacademy.com ‹#› Thefilter() Method www.webstackacademy.com ‹#› Filter() method creates a new array with all elements that pass the test implemented by the provided function. Syntax: var new_array = current_array.filter(function(currentItem,index,array) { //Application Logic to filter current array items //return items for new array });
  • 54. www.webstackacademy.com ‹#› Thefilter() Method Example: var words = ['limit', 'elite', 'exuberant', 'destruction‘]; function word(elem) { return elem.length > 6; } var result = words.filter(word); console.log(result); // expected output: Array ["exuberant", "destruction“]; www.webstackacademy.com ‹#›
  • 55. www.webstackacademy.com ‹#› Exercise www.webstackacademy.com ‹#› Write a JavaScript program to squeeze a word in given sentence. For example: 1. Input : what is what so what Output: what is so 2. Input : I mean they can't be so mean Output : I mean they can't be so 3. Input : Butler bought bitter butter but he made it as a better butter by adding sweeter butter Output : Butler bought bitter butter but he made it as a better by adding sweeter
  • 56. www.webstackacademy.com ‹#› Themap() Method www.webstackacademy.com ‹#› The map() method creates a new array with the results of calling a provided function on each element in the calling array. Syntax: var new_array = current_array.map(function(currentItem, index, array) { //Application Logic //Return elements for new array });
  • 57. www.webstackacademy.com ‹#› Themap() Method Example: var curArray = [1, 4, 9, 16];// pass a function to map var doubleArray = curArray.map(doubleItem); function doubleItem(currentItem) { return 2 * currentItem; } console.log(doubleArray); www.webstackacademy.com ‹#›
  • 58. www.webstackacademy.com ‹#› Exercise www.webstackacademy.com ‹#› Write a JavaScript program to greet the guest. For example: 1. Input : [‘Ram’,’Radhika’,’John’,’Sumit’] Output: Welcome Ram Welcome Radhika Welcome John Welcome Sumit
  • 60. www.webstackacademy.com ‹#› Multidimensional Array Declaring Multidimensional Array var array2d = [ [10, 20, 30], [40, 50, 60], [70, 80, 90] ]; for(let idx = 0; idx < array2d.length; idx++) { for(let jdx = 0; jdx < array2d[idx].length; jdx++) { document.write(array2d[idx][jdx] + " "); } document.write("<br>"); }
  • 61. www.webstackacademy.com ‹#› Exercise  WAP to find out sum of diagonal elements in a 2D array  WAP to find max and min value in a given row  WAP to multiply two matrix using 2D arrays
  • 62. www.webstackacademy.com ‹#› WebStack Academy #83, Farah Towers, 1st Floor, MG Road, Bangalore – 560001 M: +91-809 555 7332 E: [email protected] WSA in Social Media: