Publicité
Publicité

Contenu connexe

Publicité

Javascript Methods and events

  1. Javascript Methods & Events By : Omar Hussein Mohamed
  2. toString() (Array Method)  The toString() method any type of data as a string .  The toString() method doesn’t change the original string .  The toString() can be used to convert a string object into a string . let text = "Hello World!"; let result = text; // result = Hello World! //
  3. join() (Array Method)  The join() method returns an array as a string .  The join() method doesn’t change in the original array .  Any separator can be specified. The default is comma (,). const fruits = [“banana” , “Orange” , “Apple” , “Mango”]; let result = fruits.join(); // result = Banana,Orange,Apple,Mango//
  4. contact() (Array Method)  The concat() method joins two or more arrays.  The concat() method returns a new array, containing the joined arrays.  The concat() method does not change the existing arrays. const arr1 = [“Javascript” , “C++” , “PHP”]; const arr2 = [“Python” , “Kotlin” , “html”]; let result = arr1.concat(arr2) // result = Javascript,C++,PHP,Python,Kotlin,html//
  5. some() (Array Method)  The some() method checks if any of the elements in an array pass a test.  The some() method does not change the original array.  The some() method returns true (and stops) if the function returns true for one of the array elements.  The some() method returns false if the function returns false for all of the array elements. const age = [3, 10 , 18 , 20]; function check(age) { return age > 18; } let result = age.some(check); // result = true //
  6. every() (Array Method)  every() returns true if all elements in an array pass a test (provided as a function).  every() method returns true if the function returns true for all elements.  every() method returns false if the function returns false for one element.  every() method does not change the original array. const age = [32, 33 , 16 , 40]; function check(age) { return age > 18; } let result = age.every(check); // result = false //
  7. indexOf() (Array Method)  The indexOf() method returns the first index (position) of a specified value.  The indexOf() method returns -1 if the value is not found.  The indexOf() method starts at a specified index and searches from left to right. const code = [“html” , “javascript” , “python” , “php”]; let result = code.indexOf(“javascript”); // result = 1 //
  8. onmouseover (Event)  The onmouseover event occurs when the mouse pointer enters an element.  The onmouseover event is often used together with the onmouseout event, which occurs when the mouse pointer leaves the element.
  9. onmouseout (Event)  The onmouseout event occurs when the mouse pointer moves out of an element.  The onmouseout event is often used together with the onmouseover event, which occurs when the pointer is moved over an element
  10. onmousedown (Event)  The onmousedown event occurs when a user presses a mouse button over an HTML element. const text = document.createElement(‘p’); Text.innerHTML = “Hello World” Text.addEventListener(“mousedown” , ()=>{ text.style.color = “red” }) //note : in addEventListener method we use only “mousedown”//
  11. onmouseup (Event)  The onmouseup event occurs when a mouse button is released over an element. const text = document.createElement(‘p’); Text.innerHTML = “Hello World” Text.addEventListener(“mouseup” , ()=>{ text.style.color = “blue” }) //note : in addEventListener method we use only “mouseup”//
  12. Best Regards
Publicité