Javascript Course


The array_map(), and array_search() functions are generally known and used in PHP. These functions are useful when working with arrays. JavaScript has similar functions, but with other syntax.

array.map()

The array.map(callback) method returns an array containing all the elements of array after applying the callback function to each one.
- Example:
var arr = [1, 4, 9, 16];

//creates an array with the values from arr, doubled
const arr2 = arr.map((v, i)=>v*2);

console.log(arr2); //[2, 8, 18, 32]

array.indexOf()

The JavaScript array.indexOf(value) method is equivalent to the php array_search(value, array) function, it searches the array for a given value and returns the corresponding index if successful, or -1 if none is found.
- Example:
let arr =['ab', 'cd', 90];
var ixv = arr.indexOf('cd');
if(ixv !=-1) document.write('<p>arr contains the value: cd, with index: '+ixv+'</p>');

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag defines the clickable areas inside the image map?
<map> <img> <area>
<img src="image.jpg" usemap="#map1">
<map name="map1">
  <area shape="rect" coords="9, 120, 56, 149" href="#">
  <area shape="rect" coords="100, 200, 156, 249" href="#">
</map>
Which CSS property defines what is done if the content in a box is too big for its defined space?
display overflow position
#id {
  overflow: auto;
}
Click on the event which is triggered when the mouse is positioned over an object.
onclick onmouseover onmouseout
document.getElementById("id").onmouseover = function(){
  document.write("Have Good Life");
}
Indicate the PHP variable that contains data added in URL address after the "?" character.
$_SESSION $_GET $_POST
if(isset($_GET["id"])) {
  echo $_GET["id"];
}
array_map and array_search in JavaScript

Last accessed pages

  1. PHP getElementById and getElementsByTagName (49137)
  2. jQuery background position (5241)
  3. SHA1 Encrypt data in JavaScript (35315)
  4. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (137559)
  5. CSS Course - Free lessons (21684)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (248)
  2. Read Excel file data in PHP - PhpExcelReader (84)
  3. The Four Agreements (73)
  4. PHP Unzipper - Extract Zip, Rar Archives (72)
  5. The Mastery of Love (63)
Chat
Chat or leave a message for the other users
Full screenInchide