0% found this document useful (0 votes)
158 views7 pages

JavaScript String and Array Methods Guide

The document discusses various string, array, and DOM manipulation methods in JavaScript. It covers string methods like length, toUpperCase(), slice(), replace(), trim(), and concat(). It also covers array methods such as pop(), shift(), unshift(), splice(), sort(), map(), filter(), reduce(), and ways to convert objects to arrays. The document then discusses DOM navigation techniques including getting elements by ID, class, tag name and traversing the DOM tree. It also covers manipulating the DOM using innerHTML, creating elements, and adding/removing attributes.

Uploaded by

Huzaifa Awan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views7 pages

JavaScript String and Array Methods Guide

The document discusses various string, array, and DOM manipulation methods in JavaScript. It covers string methods like length, toUpperCase(), slice(), replace(), trim(), and concat(). It also covers array methods such as pop(), shift(), unshift(), splice(), sort(), map(), filter(), reduce(), and ways to convert objects to arrays. The document then discusses DOM navigation techniques including getting elements by ID, class, tag name and traversing the DOM tree. It also covers manipulating the DOM using innerHTML, creating elements, and adding/removing attributes.

Uploaded by

Huzaifa Awan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

String methods:

.length function for string length

.toUpperCase()

.slice(2,5) parameters are must

.replace(“huzaifga”,”Huzaifa”)

[Link]()---- removes empty spaces

[Link](another string name);;

[Link] on google for all string methods

.tostring();

.join(“-”)

.pop() will remove the last element of array same

.shift() // removes first letter of array

.unshift() // removes an element from start of array

.delete[i];

.concat[a,b,c,d,e]

.sort();modify original array

.splice(srart index,elements to remove,elements to add)// will add new elemets to array

[Link](a);// this will make array from obj a

For of and for in loop

For(let I of num){

[Link](i);

Map filter and reduce:


let num =[1,3,4,5,3,2];

[Link]((value,index,array)=>{

[Link](value,index,array);
})

FILTER METHOD:
.reduce() will add the elements of array

Console methods:
[Link](“this will print in red form”)

[Link](condition) // will returen true or false

[Link]()// to clear concole

[Link](obj name) will print table

Console,warn(“”)

Conso;[Link]()

[Link](label)

[Link](label)

Confirm , alert and prompt:

Prompt for input from user and store in variable

alert("enter value of a ");

let a = prompt("enter here",662);

[Link](a);

Alert : to invoke mini window

alert("hello your script works");

confirm:

gives short message with ye or no option this will return true for yes and false for no
[Link]=[Link]

walking with dom


[Link]
[Link]

typeof [Link]

[Link](for full html docum,ent)

meta tag:
meta tag is child of head

[Link]()

[Link]()

Element only navigation:

[Link]

tables:
[Link]

DOM:

Let ctitle =[Link](“abc class”);

[Link]=”red”

Let ctitle= getElementById(“id”);

GetElementByTagName(“s”)
Matches,closestand contains:
[Link](“.class”)

[Link](css)

Chapter 8
[Link] will print as an object with its properties

while [Link] will print content

>innerHTML will return inner part odf document and .innerHTML will be used to replace the text in the
old html valid only for element nodes

outerHTML

attributes in html js:

let a =[Link](“class”) // this will print the class name with respected id.

let a =[Link](“class”) // we will find that if this id has attribute class or not

[Link](“class”,”hidden”)

[Link](“class”)

for custom attributes addition data-attribute name =”value”

for accessing data attributes [Link]

for innerhtml insertion

let a = [Link](‘div’)[0]

[Link]= [Link]+ ‘<h1>hello I am inserted<h1>’;

for creating new div

let div= [Link](‘div’)


[Link]=’<h1>hello<h1>’

[Link](div)

insertAdjacantHTML(‘beforebegin’,<div class = “test”> beforebegin</div>);

insertAdjacantHTML(‘beforeend’,<div class = “test”> beforeend</div>);

insertAdjacantHTML(‘afterend’,<div class = “test”> afterend</div>);

insertAdjacantHTML(‘afterend,<div class = “test”> afterend</div>);

set interval and set timeout:

alert("hello");

let a= setTimeout(function(){

alert("i am inside the timeout function");

},2000)

clearTimeout(a) // this will clear time out

[Link](a);

dom events:

<body>

<div class ="container">

<button onclick="alert('hello ')"> Click Me </button>

</div>

<script src="[Link]"></script>

Onmouseenter:
<body>
<div class ="container" onmouseenter="alert('mouse inside container')">

<button onclick="alert('hello ')let a =6 ; [Link](a)"> Click Me </button>

</div>

Onclick

Add event listener and remove event liostner:


Call back call back hell():

Promisis for call back functions:


Let promise = new promise (function(resolve,reject){

})

[Link]((value)=>{

[Link](value)

})

Reject(new Error(“I am error”))

Promise chaining in js:

Promise API:
6 primary method:

First method if all promises are resolved then it will give final result but incase any one is not resolved
then this will not proceed

Let Promise_all= [Link]([p1,p2,p3])

Promise_all.then((value)=>{

[Link](“hello all promises are done”)})


Incase we want top return settled promises result then

Let Promise_all= [Link]([p1,p2,p3])

Promise_all.then((value)=>{

[Link](“hello all promises are done”)})

[Link] jo pehly hojay wo dyga

Async Await:
We can put our code to run

Async will return promise the

Error handling in js try and catch:


Try{

[Link](Rahul)

Catch(error){

[Link](error)

Custom error error object:


[Link]

[Link]

Throw new error(“ali is not good”)

The Finally Clause

Finally{

This piece of code inside finally block will execute under anycondition

You might also like