Sie sind auf Seite 1von 6

JavaScript tutorial :

Push :it add elements at the end of the array


Pop:It removes element from last and return the elements.
unshift:It add elements at the start of the array
Shift:It removes first element and return the elements.

If ,else, else if
Instead of above statements we use ternary.
Instead of if, if else, we use switch for code readability.

Sort for numbers we use function(a,b) return a-b;


Splice : It is used add or remove elements from an array
Syntax :Array.splice(index,delete count,item1,….,item n)
Item1,item2 for adding
Filter method: It filters and creates an new array

What is dom ?
Document.getElementByid(mbh).innerHtml=”Mounika”;
After execution by inspecting the id value can change so we use class
names to get value
But if many lines have same classes it get conflict for that we use id in
jquery by
1. ^id if id first and later any data eg:id7dfhd4
2. $id if id is last and front some other data E g:hdh634id
3. *id if any place d matches Eg :&GGJJ86id^&NH
Eg :vegetables peel cutting(variables, strings, properties etc ) last
cooking(cooking is Dom)

Red Green Blue(RGB)


#ff0000 ff-full red zero green zero blue
We cannot use directly red.

Splicing an Array

The splice() method can be used to add new items to an array:

Example

var fruits = ["Banana", "Orange", "Apple", "Mango"];


fruits.splice(2, 0, "Lemon", "Kiwi");

<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Array Methods</h2>

<h2>splice()</h2>

<p>The splice() method adds new elements to an array, and returns an


array with the deleted elements (if any).</p>

<button onclick="myFunction()">Try it</button>

<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>

<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo1").innerHTML = "Original
Array:<br> " + fruits;

function myFunction() {
var removed = fruits.splice(2, 2, "Lemon", "Kiwi");
document.getElementById("demo2").innerHTML = "New
Array:<br>" + fruits;
document.getElementById("demo3").innerHTML = "Removed
Items:<br> " + removed;
}
</script>

</body>
</html>

The slice() method slices out a piece of an array into a new array.

<html>
<body>

<h2>JavaScript Array Methods</h2>


<h2>slice()</h2>

<p>This example slices out a part of an array starting from array element
1 ("Orange"):</p>

<p id="demo"></p>

<script>
var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = fruits.slice(1);
document.getElementById("demo").innerHTML = fruits + "<br><br>" +
citrus;
</script>

</body>
</html>

Eg :JavaScript Array Methods

slice()

This example slices out a part of an array starting from array element 1
("Orange"):

Banana,Orange,Lemon,Apple,Mango

Orange,Lemon,Apple,Mango
Create an HTML element document.createElement(element)

If we want to display data from database to gridview but we don’t know


how many lines of data we have for that we use it.

addEventListener():

Instead of writing onchane in the input tag we will write event listerners.

iframe : It is used to display adds(advertisements) in a browser


while seeing w3schools javascript etc.

Domain Name:

For example, in the URL http://www.pcwebopedia.com/index.html,


the domain name is pcwebopedia.com.

www.w3schools.com is a domian name in the url.

technology examples :

 Tablets.
 Laptops.
 Communication Technology Labs.
 Interactive Whiteboards.
 Robotics.
 3-D Printers.
 Digital Cameras.
 Video Cameras.

Why we include jquery library in the head tag ?


SOLUTION :
IT CONVERTS JQUERY LANGUAGE tO MACHINE
UNDERSTANDABLE LANGUAGE I.E HTNL,CSS,JAVASCRIPT.

Var : varialbles declarared with var cannot have scope.


Let :variables declared with the let can e accesible with in the block

Variables declared with var and let are quite similar when declared inside a
function.

They will both have Function Scope:

addEventListener()

This example uses the addEventListener() method to attach a click event


to a button.

The addEventListener() method allows you to add many events to the same
element, without overwriting existing events:

Das könnte Ihnen auch gefallen