You are on page 1of 2

MDN >> the most important website to learn JS

how to get unique values from array ??


Using set object U can search for it .

Scope >>>
any variable in js are global expect the function Scope

Hoisting >>> the important thing it make the initialization of variables and
functions Up.

self invoked fun >> for local scope

//Method 1: Convert the keys to Array using - Object.keys()


let obj = { id: "1", name: "user22", age: "26", work: "programmer" };
console.log(Object.keys(obj)); // ["id", "name", "age", "work"]

// Method 2 Converts the Values to Array using - Object.values()


console.log(Object.values(obj)); // ["1", "user22r", "26", "programmer"]

to transfer from array to string we use


(localStorage.setItem('products',JSON.stringify(productsContainer));)

to transfer from string to array we use


(productsContainer = JSON.parse(localStorage.getItem('products'));)

Callback Function
fetch

use strict >>to avoid js 3abt

blockscope > means if.. for.. while.. switch (if we use var it will be global
variable but if we use let it's will be local)

js >> Having a object but not having a class

Map object >> Making the object itratable

Js api

var myHttp = new XMLHttpRequest();

var type = "all";


var duration = "day";
myHttp.open(
"GET",
`https://api.themoviedb.org/3/trending/${type}/${duration}?
api_key=0c000d6b099081fa5395d9ad879777a0`
);

myHttp.send();
var myPosts = [];
myHttp.addEventListener("readystatechange", function () {
if (myHttp.status == 200 && myHttp.readyState == 4) {
myPosts = JSON.parse(myHttp.response).results;
console.log(myPosts);

displayData();
}
});

(((((((((((
‫بدل كل الظيطه اللي فوق ديييييييييي‬

var finallynews = [];

async function getNews(){


var news = await fetch(`https://newsapi.org/v2/top-headlines?
country=us&category=business&apiKey=beac07a459ef412284498cf5be72c514`);
finallynews = (await news.json()).articles;
console.log(finallynews);
displayData();
}

))))))))))))

function displayData() {
var cartona = ``;
for (var i = 0; i < myPosts.length; i++) {
cartona += `
<div class="col-md-4">
<img src="https://www.themoviedb.org/t/p/w220_and_h330_face$
{myPosts[i].poster_path}" class="w-100 h-50">
<h1>${myPosts[i].title == null ? 'person': `${myPosts[i].title}`}
</h1>
<p>${myPosts[i].overview== null? 'that what i need':`$
{myPosts[i].overview}`} </p>
</div>
`;
}
document.getElementById("post").innerHTML += cartona;
}

///////////////////////////////////////////

You might also like