JavaScript Notes #2
console.clear();
let arr = [3,5,7,1,6,9];
arr.forEach(function(i){
console.log(i);
});
// element, index, array can be arguments.
let mixture = {
naam: "freak",
OS: 'ubuntu',
type:'intd'
};
for(let key in mixture){
console.log(`${key} of object is ${mixture[key]}`);
}
// functions::
function greet(user, thank = 'Thank You'){
return `${user}whatsup! Hope you are fine. There are tough times but still have a faith in our doctors. At last, ${thank}.`
}
let pr = greet('tejas', 'fuck off');
console.log(pr);
console.clear();
// gives data about the html loaded at the page
let a = document;
a = document.body;
a = document.forms;
a = document.all;
// console.log(a);
// a.forEach(function(element){
// console.log(element);
// }) ERROR since a is not an array
// iterating document elements using forEach
Array.from(a).forEach(function(element){
console.log(element);
})
// to extract links from a page
let links = document.links;
Array.from(links).forEach(function(element){
console.log(`This = ${element}`);
})
// web page crawler:
let find = 'javascript';
let allLinks = document.links;
let x;
Array.from(allLinks).forEach(function(element){
x = element.href;
if(x.includes(find)){
console.log(x);
}
})
// prompt alert and confirm
// let A = alert("Waring here - ");
// console.log(A);
// let ask = prompt("Enter your name: ", "GUEST");
// console.log(ask);
// let c = confirm("Are you sure you want to: ")
// loops
let arr = ["Tejas", "suraj", "anuj", "yash", "tushar"]
for(element of arr){
console.log(element);
}
// for(element in arr){
// console.log(element);
// }
let obj = {
name: "harry",
salary: 200,
channel: "CWH"
}
for(key in obj){
console.log(obj[key]);
}
// element and key are keywords in js
// DOM
// manuplating objects with the help of CSS selectors

Comments
Post a Comment